0

plz chk my code i m having error at line 35 and 36

#include <iostream>
#include <cstring>
using namespace std;

class strng
{
  char s[30];
    public:
           strng()
           {
                   strcpy(s,"");
                   }
     string getstring()
          {
             cout<<"enter the sting:";
             cin>>s;
           return s;  
                        }
     void displaystring()
     {
           cout <<"the string is:"<<s<<endl;
           }

                   
                          
                        const strng &operator+= (const strng &t);
                           };
                           const strng &strng ::operator+=(const strng &t)
                             {
                                    strng temp;
                                    strcpy (temp.s,"");
                                    
                                    strcat(temp.s,s);
                                    strcat(temp.s,t.s);
                                    s=temp;
                                    return s;
                                    }
                                    
                                    
                                    
           main()
          {
                     strng s1;
                     strng s2;
                     s1.getstring();
                     s2.getstring();
                      s1+=s2;
                     s1.displaystring();
                             

}

errors are:
35 C:\Dev-Cpp\ddd.cpp incompatible types in assignment of `strng' to `char[30]'

36 C:\Dev-Cpp\ddd.cpp invalid initialization of reference of type 'const strng&' from expression of type 'char*'

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by tkud
0
s=temp

s a char array & temp a strng object.

return s

What's the return type of operator +=? Is is char*?

Edited by vidit_X: n/a

0
s=temp

This is never possible bcos temp is an object of strng, and s is an attribute of any object of class strng.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.