101
{ USER }
posts: 55
last: 09-Apr-2008
TITLE: Inheritance Example
DESCRIPTION: Inheritance Example
Submitted: 09-Apr-2008 10:02:50 ( 38w 5d 22h ago ) Language: C++ (*.cpp *.h)
Views: 68 Lines of Code: 47 LINES
Rating:
rate: star1
star2
star3
star4
star5
dstar1
dstar2
dstar3
dstar4
dstar5  ( rated! )
  { 0.00 / 5 }
Difficulty: Intermediate
Bookmark
/* Author: 101
   Date: 09-04-2008
   Filename: 
   Description: Inheritance Example
   History: 
*/


class Person
{
public:
	Person(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 Person
{
   public:
	Mother(const string& firstName, const string& lastName) : Person(firstName, LastName);
	~Mother();
	Person* hasBaby(const string& firstName);
private:
	vector<Person*> children;
};

Person* Mother::hasBaby(const string& firstName);
{
	Person* newBaby = new Person(firstName, getLastName());
	children.pushback(newBaby);
	return newBaby;
}

int main(void)
{
   Mother sue("Sue", "Smith");
   Person joe = sue.hasBaby("Joe");
   Person 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;
}