は、次のコード例を見てみてください。なぜコンストラクタが呼び出されないのですか?
class testo
{
public:
testo()
{
cout << " default " << endl;
}
testo(const testo & src)
{
cout << "copy " << endl;
}
testo(const testo && src)
{
cout << "move" << endl;
}
testo & operator=(const testo & rhs)
{
cout << " assigment" << endl;
return *this;
}
testo & operator= (const testo && rhs)
{
cout << "move" << endl;
}
};
、これが私の機能と主なコードです:
testo nothing(testo & input)
{
return input;
}
int main()
{
testo boj1 ;
testo obj2(nothing(obj1));
return 1;
}
私はこのコードをコンパイルして実行したときに、私が見ることを期待:
default // default constructor
copy // returning from the function
move // moving to the obj2
コードが実行されているときに表示されます。
default
copy
コンパイラは、Visual C++ 2015
クラスのテストに使用したコードを追加してください。 –
移動コンストラクタ/移動割当からconst修飾子を削除してください。 – kreuzerkrieg
申し訳ありませんが、私は関数を忘れています。 – mehdi