anurag18294
anurag18294

Reputation: 99

Default and parametrised constructors

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

Answers (1)

sharptooth
sharptooth

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

Related Questions