I am trying to disable using some member functions with temporary objects. To achieve this, I declare a r-value reference overload as deleted:
struct X {};
struct A
{
A();
void f(X const& x);
void f(X&&) = delete;
};
int main()
{
A a;
X x;
a.f(X());
a.f(x);
return 0;
}
This works as expected giving a compiler error, but when I try this with constructors, it does not generate a compile-error:
struct X {};
struct A
{
A(X const&);
A(X&&) = delete;
};
int main()
{
X x;
A b(X()); // using deleted constructor
A c(x);
return 0;
}
Why is this compiling? Is the A(X const&) constructor a better match than the A(X&&) constructor?