Chloe Mullan Chloe Mullan - 1 month ago 6
C++ Question

How do I use get and set methods in c++ with an object that is initialised with new

Im trying to use get and set methods within c++ with an object that is initialised with new

Person *Person1 = new Person;
string first;
string family;
string ID;
int birth;


anyone any idea how I do this?

Ben Ben
Answer

Assuming that your Person has member functions like getFirst() you would use the dereference operator (-> or *) like this:

Person1->getFirst(); // equivalent to (*Person1).getFirst()