Jump to content
СофтФорум - всё о компьютерах и не только

operator+ c++


Recommended Posts

при компиляции появляется ошибка в строке 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;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...