Search code examples
c++constantsqualifiers

error in reference qualifier


Why I cant define this function,

int *clone() const &
{ 
    return new int(10); 
}

or

int x;
int *clone() const &&
{ 
    return new int(std::move(x)) ; 
}

I should be able to add const qualifier functions. Should I include any headers?


Solution

  • You can use the r-value reference on parameters, for example in a move assignment or move constructor. It seems clang has been trying an extension called 'called "rvalue reference for *this"', but I suggest you work through the move constructors and assignment operators first.