little_greg Posted December 1, 2009 Report Share Posted December 1, 2009 при компиляции появляется ошибка в строке st.str = st1.str + st2.str (error: invalid operands of types ‘char* const’ and ‘char* const’ to binary ‘operator+’) почему так происходит? class String { private: char* str; int len; static const int CINLIM = 80; public: String(const char* s); String(); String(const String&); ~String(); int length() const {return len;} String& operator=(const String&); String& operator=(const char*); char& operator[](int i); const char& operator[](int i) const; friend String operator+(const String& st1, const String& st2); friend bool operator<(const String& st1, const String& st2); friend bool operator>(const String& st1, const String& st2); friend bool operator==(const String& st1, const String& st2); friend std::ostream& operator<<(std::ostream& os, const String& st); friend std::istream& operator>>(std::istream& is, String& st); static int howmany(); String stringup(); void stringlow(); int has(char); }; String operator+(const String& st1, const String& st2) { String st; st.str = new char[strlen(st1.str) + strlen(st2.str) + 1]; st.str = st1.str + st2.str; //error: invalid operands of types ‘char* const’ and ‘char* const’ to binary ‘operator+ return st; } ... int main() { String s1("string1"); String s2 = "string2"; String s3; s3 = s2 + s1; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.