close

Inheritance in C++ takes place between classes. When one class inherits from another, 

the derived class inherits the variables and functions of the base class. 

These variables and functions become part of the derived class.

For simple explanation , we only use public for our example :

class BaseballPlayer
{
public:
    double m_dBattingAverage;
    int m_nHomeRuns;
};
// BaseballPlayer publicly inheriting Person
class BaseballPlayer : public Person
{
public:
    double m_dBattingAverage;
    int m_nHomeRuns;
 
    BaseballPlayer(double dBattingAverage = 0.0, int nHomeRuns = 0)
       : m_dBattingAverage(dBattingAverage), m_nHomeRuns(nHomeRuns)
    {
    }
};

 

ref :http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 JerryCheng 的頭像
    JerryCheng

    KwCheng's blog

    JerryCheng 發表在 痞客邦 留言(0) 人氣()