+ 6
What is getname setname? In c++
2 Antworten
+ 5
Here is an example:
class Person{
string name;
public:
string getName(){
return name
}
void setName(string newName){
name = newName;
}
};
int main(){
// create an object Person (see your other
// question
Person p1;
//set the name of p1 to Jimmy
p1.setname("Jimmy");
//get the name of object p1
cout << p1.getName();
}
If anything is unclear feel free to ask.