I tried to understand how this allocation works in c++ :
Test other = toto();
This is the full code source :
#include <iostream>
class Test
{
public:
Test()
{
j = i++;
std::cout<<"default constructor "<<j<<std::endl;
}
Test(const Test&)
{
std::cout<<"constuctor by copy "<<j<<std::endl;
}
Test & operator=(const Test&)
{
std::cout<<"operator = "<<j<<std::endl;
return *this;
}
int j;
static int i;
};
int Test::i = 0;
Test toto()
{
Test t;
return t;
}
int main()
{
Test other = toto();
std::cout<<other.j<<std::endl;
Test another;
return 0;
}
The code not used constructor by copy or operator =, so I don't understand really how it's works ... I used gcc 4.7.0
Thranks for your help :)
Jerome