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 3 of 3.

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

#include<iostream.h>
#include<conio.h>
class Anil
{
private:
int a;
public:
Anil(int A)
{
a=A;
cout<<"values is"<<A<<endl;
}
};
int main()
{
Anil A();
getch();
return 0;
}

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.


Post your comments here:

Your comments will be displayed after verification.