Set with Custom String Class Problem
I have written a custom string class. I want to use STL set with it. I have overloaded operator < But still its giving me problem
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)'
I guess, It is asking for overloaded operator= (const String , const String)
But its im开发者_JS百科possible to create such an overloaded function
My String class is 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 ();
"no operator found which takes a left-hand operand of type 'const String'"
it seem you have an expression like
a=b;
where both a
and b
are const String
.
You cannot assign to a const (although the compiler looks desperately seeking for an implementation of such an assignment)
OK, well I can only answer the question you've posed with the information you've given, and the answer is that this works for me.
精彩评论