Procedure is as follows: is the thumb on the right side of the other code, the string followed "& amp;" , like and reference not
CodePudding user response:
Returns the reference,CodePudding user response:
If so you can access the private members of the base class, but how specific operation, he and the preceding function elegantly-named setName () is supporting you, that is, the member function in a subclass, as long as the call elegantly-named setName () function, already can access private members in the base class, namely string& GetName () function returns the valueCodePudding user response:
I think here is not necessary to use references, with reference to have side effects (the reference try) ://Note: Your choice is a c + + IDE
#include
#include
using namespace std;
The class Person
{
Private:
string name;
Public:
The Person (string name)
{
This - & gt; Name=name;
}
String& GetName ()
{
return name;
}
};
Int main ()
{
The Person p1 (" Tom ");
CoutP1. The getName ()="Mike";
Coutreturn 0;
}
By getName () to modify the name, this should not expect,
You what is the name of the book, the author?