Presentation is loading. Please wait.

Presentation is loading. Please wait.

Inheritance Constructors & Overriden Functions

Similar presentations


Presentation on theme: "Inheritance Constructors & Overriden Functions"— Presentation transcript:

1 Inheritance Constructors & Overriden Functions

2 More than meets the eye Objects always contain copy of parent class:

3 Constructing/Destructing
Object built/destroyed in layers Base class constructed Geometric Object

4 Constructing/Destructing
Object built/destroyed in layers Base class constructed Derived class constructed Geometric Object Circle

5 Explicit Constructor Calls
Initialization list can specify parent constructor:

6 Implicit Constructor Call
If no explicit call to parent constructor, get default added behind the scenes: Silently becomes

7 When you have to… If a class does not provide no-arg constructor child classes must explicitly call one

8 When you have to… If a class does not provide no-arg constructor child classes must explicitly call one

9 When you have to… If derived class wants to set private variable and there is no set function:

10 When you have to… Pass appropriate info to parent constructor, use rest to initialize your values

11 Initialization List Can still use initializations list for own info

12 Constructing/Destructing
Object built/destroyed in layers Base class constructed Derived class constructed Geometric Object Circle

13 Constructing/Destructing
Object built/destroyed in layers Base class constructed Derived class constructed Derived class destroyed – clean up after itself Geometric Object

14 Constructing/Destructing
Object built/destroyed in layers Base class constructed Derived class constructed Derived class destroyed – clean up after itself Base class destroyed – clean up after itself

15 Overriden Functions

16 Function Implementations
Functions redefined by child class normally use that version Geometric Object Circle

17 Function Implementations
Scope resolution operator allows access to parent class version: Geometric Object Circle

18 Function Implementations
Derived class can call Parent version Avoids code duplication!


Download ppt "Inheritance Constructors & Overriden Functions"

Similar presentations


Ads by Google