设置自定义字符串类问题
Set with Custom String Class Problem
我写了一个自定义字符串类。我想用STL集合它。我已经重载了操作符<但它仍然给我的问题>但它仍然给我的问题>
error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const String' (or there is no acceptable conversion)
1> could be 'String &String::operator =(const String &)'
1> 'String &String::operator =(const char *)'
1> 'String &String::operator =(const wchar_t *)'
1> while trying to match the argument list '(const String, const String)'
我猜,它要求重载操作符= (const String, const String)
但是创建这样一个重载函数是不可能的
我的String类是this
String ();
String (const char * pStr);
String (const long int pData);
String (const double pData);
String (const int pData);
String (const wchar_t * pStr);
//Copy Constructors
String (const String& rhs);
String (const String& rhs, const int pStartIndex, const int pNumChar);
//Overloaded Operators
String & operator= (const String & rhs);
String & operator= (const char * rhs);
String & operator= (const wchar_t * rhs);
String operator+ (const String& rhs);
//String & operator+= (const char ch);
String & operator+= (const String& rhs);
friend bool operator== (const String& lhs, const String& rhs);
friend bool operator< (const String& lhs, const String& rhs) {
return strcmp(lhs.vStr, rhs.vStr);
}
friend ostream& operator<< (ostream& ostr, String& rhs);
char & operator[] (int pIndex);
char operator[] (int pIndex) const;
const char * String::Buffer () const;
wchar_t * GetTChar();
int String::GetLength () const;
~String ();
"未找到左手操作数类型为'const String'"
似乎你有一个表达式像
a=b;
,其中a
和b
都是const String
。
不能给const赋值(尽管编译器会拼命寻找这样的赋值实现)
好吧,我只能用你提供的信息来回答你提出的问题,答案是这对我来说是可行的
相关文章:
- 编译包含字符串的代码时遇到问题
- setlocale的C++土耳其字符串问题
- 当我尝试添加 2 个大字符串时,我无法弄清楚出了什么问题
- 使用自定义比较函数使用std::sort()对矢量字符串进行排序时出现问题
- 我的逻辑反转字符串中的元音有什么问题?
- 按字母顺序对C++问题中的子字符串索引进行分区
- 用户输入字符串的文件附加问题..C++
- 使用 minijson-reader 库读取 JSON 字符串时出现问题
- 在将字符串放入字符串向量时遇到问题?
- 将文件复制到自定义位置,存在字符串转换问题
- 从 argv[1] 转换为字符 * 字符串后有什么问题?
- 不确定出了什么问题(字符串输入)
- 反向和计数字符串的 C++ 问题
- 反转具有返回值的字符串时出现问题
- C++字符串问题-如何访问字符串元素
- public:静态常量字符串声明/初始化问题
- 在MySql中使用字符串操作函数有什么问题
- Libwesockets.h:lws_write:C++字符串到C的转换和发送问题
- 问题:字符串在另一个字符串上写入
- 日志文件输出的问题-字符串和c_str之间的差异- c++