Inheritance Example.
class pop{
public:
pop(const string& firstName, const string& lastName) : _firstName(firstName), _lastName(lastName);
string getFirstName() { return _firstName;};
string getLastName() { return _lastName;};
private:
string _firstName;
string _lastName;
}
class Mother : public pop
{
public:
Mother(const string& firstName, const string& lastName) : pop(firstName, LastName);
~Mother();
pop* hasBaby(const string& firstName);
private:
vector<Person*> children;
};
pop* Mother::hasBaby(const string& firstName);
{
pop* newBaby = new Person(firstName, getLastName());
children.pushback(newBaby);
return newBaby;
}
int main(void)
{
Mother sue("Sue", "Smith");
pop joe = sue.hasBaby("Joe");
pop kay = sue.hasBaby("Kay");
cout << "Baby Joe's last name is: " << joe.getLastName() << endl;
cout << "Baby Kay's last name is: " << kay.getLastName() << endl;
return 0;
}
No comments:
Post a Comment
Vulgar language in this blog is PROHIBITED....