Machineboy空
Object-Oriented Data Structures # WEEK04 : Inheritance 상속 본문
4.6 Inheritance
Inheritance allows for class to inherit all member functions and data from a base class into a derived class.
Generic to Specialized
A base class is a generic form of a speciallized, derived class.
without having to rewrite logic,
Initialization
When a derived class is initialized, the derived class must construct the base class:
- Cube must construct Shape
- By default, uses default constructor
- Custom constructor can be used with an initialized list
Access Control
When a base class is inherited, the derived class:
- Can access all public members of the base class
- Can not access private members of the base class
Initializer List
The syntax to initialize the base class is called the initializer list and can be used for several purposes:
- Initialize a base class
- Initialize the current class using another constructor
- Initialize the default values of member variables
one parameter constructor initialize private member variables without ever having to do anything in the code itself. it' s a way to clean up our code into reuse a lot of our code,
As we build more and more data structures, we're going to start building small pieces that we can injerit from to build bigger and bigger systems and more complicated data structures without having to think of all of logic.