I was asked a question because the class has multiple constructors, but why does it only have one destructor?
I gave an example below,
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); The destructor that gets the name will be called so there will be only one object at a certain point in time. I ran the code above on my PC, but it gave me the result as
Default
Int
Destructor
Destructor
If so, then why do we have one destructor?
source
share