About base class in derived class initialization

后端 未结 5 1782
醉梦人生
醉梦人生 2021-01-24 10:41

guys. I see several cases like:

class Derived:public Base{

public:
    Derived(...):Base(...){}
}

Is what situation or is there any principle

5条回答
  •  囚心锁ツ
    2021-01-24 11:24

    In case if we need to pass the arguments of derived constructor to the base constructor, it can be used.

    class foo
    {
        public:
            foo() {} 
            foo( int num ) {}
    };
    
    class bar : public foo
    {
        public:
            bar(int barNum): foo(barNum) {}
    };
    

提交回复
热议问题