C++ 设置自定义字符串类的问题

C++ 设置自定义字符串类的问题,c++,operator-overloading,set,C++,Operator Overloading,Set,我已经编写了一个自定义字符串类。 我想用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 St

我已经编写了一个自定义字符串类。 我想用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)'
我猜,它要求重载运算符=(常量字符串,常量字符串)

但是创建这样一个重载函数是不可能的

我的弦乐课是这个

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 ();
String();
字符串(常量字符*pStr);
字符串(const long int pData);
字符串(常量双pData);
字符串(const int pData);
字符串(常量wchar\u t*pStr);
//复制构造函数
字符串(常量字符串和rhs);
字符串(常量字符串和rhs、常量int pStartIndex、常量int pNumChar);
//重载运算符
字符串和运算符=(常量字符串和rhs);
字符串和运算符=(常量字符*rhs);
字符串和运算符=(常量wchar\u t*rhs);
字符串运算符+(常量字符串和rhs);
//字符串和运算符+=(常量字符ch);
字符串和运算符+=(常量字符串和rhs);
友元布尔运算符==(常量字符串和lhs、常量字符串和rhs);
friend bool运算符<(常量字符串和lhs、常量字符串和rhs){
返回strcmp(左S.vStr,右S.vStr);
}
friend ostream&operator“未找到采用“常量”字符串”类型的左操作数的运算符”

看起来你的表情像

a=b;
其中
a
b
都是
const String


你不能赋值给一个常量(尽管编译器看起来在拼命寻找这样一个赋值的实现)

好的,我只能用你给出的信息回答你提出的问题,答案是这样的。

请添加一些最小但完整的代码来演示这个问题。您遇到的实际问题可能与您认为的问题无关。我的第一个猜测是,您正在尝试创建一个
,而不是
,但如果没有更多信息,很难判断。不,我使用的是
集变量,不,我不想打印字符串。这个错误可能是在转移视线。你能给我们看看你的
字符串
类吗?(并解释为什么您不使用
std::string
)我们使用自定义字符串类,因为我们被告知要执行soyes,这是我无法理解的,不可能用两个常数来创建opeartor=arguments@Sumit:您很可能在某个地方误用了
std::set
,这导致编译器需要这样一个不可能的重载,例如试图在set中赋值。字符串类本身可能是正常的。@Sumit:是的,您不能创建该运算符,但编译器需要在某个地方使用它。问题不在于字符串,而是你用它做了些什么。