Compiler Generated Default Constructor :
In C++ 3.0 : Compiler results an error if there any other constructor and missing default constructor and you try to invoke default constructor.
class CAT {
CAT(int age) {}
};
CAT d1; // Error: compiler will not generate the default constructor
// C++ 11: With the default keyword, it forced the compiler to generate default constructor even if the is any other constructor.
class CAT {
CAT(int age);
CAT() = default; // Force compiler to generate the default constructor
};
In C++ 3.0 : Compiler results an error if there any other constructor and missing default constructor and you try to invoke default constructor.
class CAT {
CAT(int age) {}
};
CAT d1; // Error: compiler will not generate the default constructor
// C++ 11: With the default keyword, it forced the compiler to generate default constructor even if the is any other constructor.
class CAT {
CAT(int age);
CAT() = default; // Force compiler to generate the default constructor
};
Comments
Post a Comment