开发者

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 );
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜