Default and parametrised constructors
Is this statement true that declaring a constructor with arguments hides the default constructor and you cannot invoke the defaul开发者_如何学Ct constructor.
Not exactly. Instead it suppresses the generation of compiler-provided default constructor. Consider:
class Class1 {
};
Class1 will have a compiler-generated default constructor, so you can call new Class1(), while
class Class2 {
Class2( int );
}
will not have a compiler-generated default constructor. So you can't call new Class2() unless you explicitly declare a default constructor for Class2:
class Class2 {
public:
Class2();
Class2( int );
}
加载中,请稍侯......
精彩评论