C++ Programming - Constructors and Destructors - Discussion

Discussion Forum : Constructors and Destructors - General Questions (Q.No. 2)
What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero-argument constructor?
Compile-time error.
Preprocessing error.
Runtime error.
Runtime exception.
Answer: Option
No answer description is available. Let's discuss.
22 comments Page 1 of 3.

Sagar said:   12 months ago
By default only the constructors are called, but not the destructors because when we create the object of the class it calls the constructor only not the zero argument destructor.

Anil said:   5 years ago
As per my knowledge; it should be.

class Anil
int a;
Anil(int A)
cout<<"values is"<<A<<endl;
int main()
Anil A();
return 0;

Sisman said:   5 years ago
First, what is the difference between run time and compile time? Please explain me.

Srikanth.m said:   6 years ago
Why constructor error generates at compile time?

Venkat said:   8 years ago
Why constructor error generates at compile time?

M Uzair said:   8 years ago
When a class create object by default called implicit default constructor which may be parameterlessor with all parameter with default value, and if parameterized constructor is provided but no call made to that parameterized constructor explicit then compiler cannot create object and give compile time error.

Shubam13 said:   8 years ago
Constructors initializes the object and the initialization of the object is done at compile time as we have created the parametrized constructors the class will not use its default constructors and the object we created is with zero arguments.

So during the compile time when constructor tries to initialize the object it will show and error and as this error took place during compilation the option A is correct.

Anand Prasad said:   9 years ago
The answer would be different if the class has unparameterized constructor because default constructor are generate only when there are no parameterized constructors.

Manish said:   9 years ago
When object is created constructor initialize the object. When we create parameterized constructor it requires argument and when compiler finds no arguments passing through the obj it leads compilation error.

Sonu Rajpoot said:   9 years ago
Compile time error:- (Why), As we know constructor fired when object is created, at the same time compiler check for default constructor if you are not declare any constructor in your code, otherwise, on same time compiler ignore call for default constructor it make a call for user defined constructor.

Object is created at compile time, that's why error occur at compile time. (Some time object may be create at run time for to achieve run time polymorphism).

Post your comments here:

Your comments will be displayed after verification.