この右辺値呼び出しがあいまいなのはなぜですか? 私は AA と AA& を持つことができ、コンパイラは を使用することを認識しますAA&
。しかし、3 番目のオプションを追加すると、エラーが発生します。明らかに AA&& は、int の int のような他のものよりも優れたオーバーロードであり、long よりも優れています。なぜこれがあいまいなのですか?3 つのオーバーロードすべてを保持し、どれが必要かを明確にする方法はありますか? (型キャスト(AA&&)
はそれを行いません)。
struct AA{
void*this_;
AA() { this_=this; }
//not valid, use AA&, AA(AA a){ this_=this; }
AA(AA&a){ this_=this; }
AA(AA&&a){ this_=a.this_; }
};
void movetest(AA s) {}
void movetest(AA& s) {}
//This gets me the ambiguous error void movetest(AA&& s) {}
AA&& movetest() { return AA(); }
void MyTestCode2(){
AA a;
AA b(a);
AA c = movetest();
movetest(AA());
}