-5

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?

Chloe Mullan
  • 3
  • 1
  • 6

2 Answers2

1

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

Person1->getFirst(); // equivalent to (*Person1).getFirst()
Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175
0

You need to define the setters and getters in your class, as well as you should define your members there

something like:

class person{

public:

person(){}

~person(){}

here put your getter and setter like...
void setFirst(...) { .... }
string getFirst() { return ... }
...

private:

string first;
string family;
string ID;
int birth;

}

retinotop
  • 483
  • 11
  • 17