I am sure , I am missing a simple thing here ,
I am not not able to call copy constructor in the code. What can be the reason ?
Is compiler optimizing my code ?
#include<iostream>
using namespace std;
class Test
{
public:
int x;
Test(){
x=100;
cout << "Test() Called\n";
}
Test(const Test &t) {
this->x=t.x;
cout << "Test-Copy() Called\n";
}
};
Test fun()
{
cout << "fun() Called\n";
Test t;
return t;
}
int main()
{
Test t1;
Test t2 = fun();
cout<<t2.x<<endl;
return 0;
}