#include <iostream>
using namespace std;
class foo {
public:
foo() {}
foo(const foo& other) {cout << "foo's copy constructor " << endl;}
foo(foo&& other) {cout << "foo's move constructor " << endl;}
foo(const foo&& other) {cout << "foo's move constructor with const ref ref" << endl;}
};
class bar {
public:
bar(const foo& f) : f_(move(f)) {}
foo f_;
};
int main()
{
foo f;
bar b(f);
}
In the above code, in absence of the move constructor -- foo(const foo&& other), the rvalue reference move(f) is implicitly converted into a const reference and thus foo's copy constructor is called.
My question is why a const rvalue reference implicitly converted into a const reference instead of a compiler error? Specifically, if I comment out the last move constructor, then foo's copy constructor is called.