C++ Programming - Constructors and Destructors - Discussion

Discussion Forum : Constructors and Destructors - General Questions (Q.No. 2)
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
Explanation:
No answer description is available. Let's discuss.
Discussion:
22 comments Page 2 of 3.

Manish said:   1 decade 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.

Sagar said:   3 years 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.

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

Pragya said:   1 decade ago
Compile time error. Because constructor error always generated at compile time. Compiler use to create default constructor if default constructor is not provided.

Naveen said:   1 decade ago
It depends on compiler also. Some compilers allow us to create a class without default constructors and it will created automatically during run time.

Navin said:   1 decade ago
I agree with Naveen. Compiler use to create default constructor if default constructor is not provided.

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

DWARIKA said:   1 decade ago
Compile time error, because constructor error generally generated at compile time.

Lalit said:   1 decade ago
Because, when we build an object, then the constructor is call.

Venkat said:   1 decade ago
Why constructor error generates at compile time?


Post your comments here:

Your comments will be displayed after verification.