ここで、creator()は、私が逆参照してfooに渡すXへのポインタを返します。それは右辺値なので、移動セマンティクスを使用する必要があります。しかし、私はそれを実行すると、私はfoo(X &)が呼び出されることがわかります。C++:foo(X &&)の代わりにfoo(X&)が呼び出されるのはなぜですか?
#include <iostream>
using namespace std;
struct X {
int i;
};
void foo(X& x) {
cout << "foo(X&)" << endl;
}
void foo(X&& x) {
cout << "foo(X&&)" << endl;
}
struct X* creator() {
return new X {5};
}
main() {
X x{5};
foo(*creator()); // prints foo(X&)
}
http://en.cppreference.com/w/cpp/language/operator_member_access#Built-in_indirection_operator – chris