I have a program which is showing weird behaviour
#include <cstdlib>
#include <iostream>
using namespace std;
class man{
int i ;
public:
man(){
i=23;
cout << "\n defaul constructir called\t"<< i<<"\n";
}
man (const man & X) {
i = 24;
cout << "\n COPY constructir called\t"<< i<<"\n";
}
man & operator = (man x ) {
i = 25;
cout << "\n = operator called\t"<< i<<"\n";
return *this;
}
};
int main(int argc, char *argv[])
{
man x;
cout <<"\n ----------\n";
man y = x;
cout <<"\n ----------\n";
x=y;
return 0;
}
The output shown in
defaul constructir called 23
----------
COPY constructir called 24
----------
COPY constructir called 24
= operator called 25
This output is weird for the third call of x=y ;
Why is there an extra print of copy construtor called when I did not made a new object but am working with old objects .
Is it becuase of temporary objects in between and if yes can i stop them here ....