Reputation: 99
Is this statement true that declaring a constructor with arguments hides the default constructor and you cannot invoke the default constructor.
Upvotes: 0
Views: 102
Reputation: 170489
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 );
}
Upvotes: 8