A Class With Objects of Another Class as Private Members

I have a class derived from a base class with a constructor. This class itself has its own constructor to initialize its private members which consist solely of objects of another class which is derived from the same base class. My problem is that I have no clue how to declare and define the constructor in the header file and implementation file to initialize the values of the class objects. This is something similar to what I am looking at:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Base
{
     public:
                 Base(const string& name, const int& age);
                 //More functions
     private:
                 string TheName;
                 int TheAge;
}

class DerivedOne : public Base
{
     public:
                 DerivedOne(const string& name, const int& age, const int& height, const int& weight);
                 //More functions
     private:
                 int TheHeight;
                 int TheWeight;
}

class DerivedTwo : public Base
{
     public:
                  DerviedTwo(const string& name, const int& age,     //Unsure how to complete this declaration
                  //More functions
     private:
                  DerivedOne Object1;
                  DerivedOne Object2;
                  DerivedOne Object3;
}
You need to pass 3 sets of name, age, height, weight, plus DerivedTwo's own name and age.
Topic archived. No new replies allowed.