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?
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?
Assuming that your Person
has member functions like getFirst()
you would use the dereference operator (->
or *
) like this:
Person1->getFirst(); // equivalent to (*Person1).getFirst()
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;
}