私はこの割り当てがC++でどのように機能するかを理解しようとしました:
Test other = toto();
これは完全なコードソースです:
#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;
}
コピーまたは演算子=によってコンストラクターを使用していないコードなので、実際にどのように機能するのかわかりません...gcc4.7.0を使用しました
あなたの助けのためにThranks:)
ジェローム