C++ Foundation —— (07) C++14 Call Constructor in Constructor
»
    In Java, there is a function called this(a,b,c). It's used to construct a Object calling another constructor function with different parameters.

    In C++, then, How to call other constructors in a constructor function?
    Don't worry. Here we go.
    C++ has the constructor function followed by colon, and has the class definition followed by colon too.
    In C++, colon means 'extending from', means the constructor is extending from other constructor, means a class is extending from other class.
    This is what I'm keeping using in my coding. This is what I know.

    class Car:Vehical{
    private:
        int type;
        std::string name;
    public:
        Car(std::string name):Car(name,1){
        }
        Car(std::string name,int type):Vehical(name,type){
            this->name=name;
            this->type=type;
        }
    }
            
«
--Alex.Zhang
--www.v-signon.com Learningers Co-Encouraged
Back
Personal Art: www.up-task.com Unit: Individual
中文 Русский 京ICP备19038994号-2
If the content on this website infringes upon your any rights, please contact me at 1307776259@qq.com for removal