#include<iostream>
using namespace std;
struct B{};
struct A
{
A(const B &)
{
cout<<"A(const B &)"<<endl;
}
A(B &&)
{
cout<<"A(B &&)"<<endl;
}
};
A get()
{
B b;
return b;
}
int main()
{
get();
}
I tested the code with VC++14.2 and GCC 5.4.0, both of them output:
A(B &&)
Why is the output not
A(const B &)
?
Does this code have any relation with copy elision
? (But A and B are different types, so copy elision
should not work here)