I have been asked a question as, a class has multiple constructors
but why it has only one destructor
?
I gave below example,
class abc
{
public:
int a;
abc()
{
cout << "Default\n";
}
abc(int)
{
cout << "Int\n";
}
~abc()
{
cout << "Destructor\n";
}
};
int main()
{
abc ab;
abc a(5);
}
And I explained as before abc a(5); gets called destructor will get called so, there will only one object at a particular point of time. I ran the above code now in my PC but it gave me output as
Default
Int
Destructor
Destructor
If this is so then why do we haveone destructor
?