Question: Question 1.2 Forward declaration Write the following forward class declarations for Parent and Child. class Child; // forward statement that class Child exists class Parent;

Question 1.2 Forward declaration

Write the following forward class declarations for Parent and Child.

class Child; // forward statement that class "Child" exists

class Parent; // forward statement that class "Parent" exists

class Parent {

public:

Parent();

string getName() const;

void setName(string n);

void addChild(const Child &c);

int numChildren() const;

const vector& getChildren() const;

private:

string name;

vector children;

};

class Child {

public:

Child(string n, int a, const Parent &pt);

string getName() const;

int getAge() const;

const Parent* getParent() const;

private:

string name;

int age;

Parent p;

};

The Parent and Child class mention each other, but do not do anything.

The function bodies have not been written yet.

In the Parent class, the reference to the vector for getChildren() is const because we do not want an external application to change somebodys children.

In the Child class, the pointer for getParent() is const because we do not want an external application to change somebodys parent.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!