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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started