Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions

Question

4. Who should be invited to attend?

Answered: 1 week ago

Question

7. How will you encourage her to report back on the findings?

Answered: 1 week ago

Question

Were the decisions based on appropriate facts?

Answered: 1 week ago