i am trying to overload +operator to concat 2 strings
i tried to write a code but it is giving 2 errors and i am also not sure whether logic is correct..MY CODE is
#include<iostream.h>
#include<conio.h>
#include<string.h>
class string
{
char *str;
public:
string()
{
cout<<"enter string";
cin>>str;
}
void display()
{
cout<<str;
}
friend string operator + (string,string);
};
string operator + (string a,string b)
{
string c;
int m=strlen(a.str);
strcpy(c.str,a.str);
c.str[m]=" "; //error:cannot convert char * to char
m++;
for(int len=m+1;b.*str!='\0';len++) //error:undefined symbol str
{
c.str[len]=b.*str;
b.str++;
}
return(c);
}
void main()
{
string p,q,c;
c=p+q;
c.display();
getch();
}