我不完全确定为什么会产生该错误:
const class MyString {
public:
MyString() { _len = 0; _str = NULL; }
MyString(const char* in);
MyString(const MyString&);
~MyString();
int set(const char*);
int set(const MyString&);
int setLength(int len) { _len = len; return 0; }
int getLength() { return _len; }
char * getStr() { return _str; }
int getStr(char* out) const;
MyString operator+(const MyString & in);
MyString operator+(const char* in);
MyString operator+(const char in) {const char* temp = ∈ return *this + temp; }
MyString operator=(const MyString & in)
{ this->set(in); return *this; }
MyString operator=(const char* in)
{ if(in) this->set(in); return *this; }
MyString operator=(const char in) {const char* temp = ∈ return *this = temp; }
MyString operator+=(const MyString & in)
{ this->set(*this + in); return *this; }
MyString operator+=(const char* in)
{ if(in) this->set(*this + in); return *this; }
MyString operator+=(const char in) { return (*this + in); }
int operator==(const MyString& in);
int operator!=(const MyString& in);
int operator==(const char* in);
int operator!=(const char* in);
friend ostream& operator<<(ostream& os, const MyString & in)
{ os << in._str; return os; }
protected:
char * _str;
int _len;
};
错误正在最后一行生成。该定义之前的唯一代码是“标准”#includes 和 using namespace std。