Home > Back-end >  An array of strings
An array of strings

Time:03-24

How can I modify to make him calls the constructor? Textbooks code error is no
 
The class s {
Public:
S () {
* STR='\ 0'; Len=0;
}
S (char * PSTR)
{
Strcpy (STR, PSTR); Len=strlen (PSTR);
}
Char * gets () {
return str;
}
Int getLen ()
{
Return len.
}
S operator + obj (s);
Private:
Char STR [100].
Int len.

};
S s: : operator + obj (s)
{
Strcat (STR, obj. STR);
return str;
}
Int main ()
{
S obj1 (" Visual ");
S obj2 (" c + + ");
S obj3 (" language ");
Obj3=obj1 obj2 + + obj3;
Cout & lt; <"Obj3. STR=" & lt; Cout & lt; <"Obj3. Len=" & lt; }

CodePudding user response:

references the building Lord black sister _ reply:
how do I modify to make him calls the constructor? Textbooks code error is no
 
The class s {
Public:
S () {
* STR='\ 0'; Len=0;
}
S (char * PSTR)
{
Strcpy (STR, PSTR); Len=strlen (PSTR);
}
Char * gets () {
return str;
}
Int getLen ()
{
Return len.
}
S operator + obj (s);
Private:
Char STR [100].
Int len.

};
S s: : operator + obj (s)
{
Strcat (STR, obj. STR);
return str;
}
Int main ()
{
S obj1 (" Visual ");
S obj2 (" c + + ");
S obj3 (" language ");
Obj3=obj1 obj2 + + obj3;
Cout & lt; <"Obj3. STR=" & lt; Cout & lt; <"Obj3. Len=" & lt; }

S obj1 (" Visual "); This line is changed to obj1=new s (" Visual "); Give it a try, I am also a small white
  • Related