[C++] How do I create a child class and use setters/getters with it? via /r/learnprogramming


[C++] How do I create a child class and use setters/getters with it?

Hi all,

I am trying to create an instance of a class, then the constructor of that class creates a child object. But I cant seem to figure out how to access getters/settings in that child object? here are some code fragments:

 Animal bird(color, age, speed); 

then in the constructor for bird I create a duck object:

Animal::Animal(string color, int age, double speed){ Duck bill(speed); //I can access getters and setters for bill here (within the constructor) } //But not here.... where my getters/setters are for the bird object... how can I access "bill" object from here, so that when I call getters/setters of the Animal object I can have those getters/setters change parameters of the child object bill? 

Like for example if I want to change bill's speed by calling a setter of the Animal object?

Submitted July 12, 2017 at 08:44PM by Chrushev
via reddit http://ift.tt/2t5Isd7

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s