Hi all,
I need to design and implement a String class for the given code, and this class should store the string in a dynamically allocated memory.
Code:
int main()
{
String s1, s2 = "Done!";
X = "Well " + s2;
cout << s1 << endl;
return 0;
}
I'm getting confused in overloading "+" operator. Here's my work...
Code:
class String
{
private:
enum { size = 80 };
char str[SZ];
public:
String()
{
str[0] = '\0';
}
String(char s[])
{
strcpy(str, s);
}
String operator + (String s1) const
{
String a;
strcpy(a.str, str);
strcat(a.str, s1.str);
return a;
}
};
Any help please?