#include<iostream>
using namespace std;
class Test
{
private:
int x;
public:
Test(int i)
{
cout<<"Conversion constructor called..."<<endl;
x = i;
}
~Test()
{
cout<<"Destructor called..."<<endl;
}
void show()
{
cout<<" x = "<<x<<endl;
}
};
int main()
{
Test t(20);
t.show();
t = 30;
t.show();
return 0;
}
output:
Conversion constructor called...
x = 20
Conversion constructor called...
Destructor called...
x = 30
Destructor called...
When i am doing t = 30 why it is calling constructor and destructor? Please explain.Many thanks in advance.