I’m trying to understand the new C++ 11 features; more specifically, the reference qualifiers (one of which) restricts the assignment onto rvalues. But for some reason I can’t get this code to work. The errors I get arise when I assign the A object a to the lvalue x ( a = x ).
prog.cpp:5:47: error: expected initializer before
'&'token
prog.cpp: In function'int main()':
prog.cpp:15:9: error: no match for'operator='in'a = x'
prog.cpp:3:10: note: candidate is:A& A::operator=(const A&)
struct A {
template <typename T> auto operator = (T) & -> A & {
return *this;
}
};
int main() {
A a;
int x = 4;
a = x;
}
The code works when I take the reference qualifier out. What could I be doing wrong?
Seems you’re using GCC. Ref-qualifiers are currently only supported by Clang 3.1+. Your code compiles perfectly fine with that.