私は最近c++を使い始め、 c++11の機能を学ぶことにしました。しかし、C++ コードがどのように実行されるかは、あまり具体的でない場合があります。
以下は私のコードです。の部分でdecltype(std::move(sample)) sample2 = std::move(sample);、この行が移動コンストラクターを呼び出さない理由がわかりません。理由を説明していただけますか?
#include <iostream>
class AAA
{
public:
AAA() { std::cout << "default constructor" << std::endl; }
AAA(const AAA& cs) { std::cout << "copy constructor" << std::endl; }
AAA(AAA&& cs) { std::cout << "move constructor" << std::endl; }
~AAA() { std::cout << "destructor" << std::endl; }
};
int main(int argc, char* args[])
{
AAA sample;
// ((right here))
decltype(std::move(sample)) sample2 = std::move(sample);
return 0;
}
[gcc 5.4.0]を使用して[ubuntu 16.04 LTS]でコンパイルされています