Why is this rvalue call ambiguous? I can have AA and AA& and the compiler will know to use AA&
. But when i add in the third option i get an error. Obviously AA&& is a better overload then the others like int for an int is better then long. Why is this ambiguous? Is there a way i can keep all 3 overloads and make it clear which one i want? (Typecasting (AA&&)
will not do it).
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());
}