I found the C++ class with API like this:
class foo
{
.....
public:
int& func1() & ;
int func1() && ;
.....
}
what does operator & and && do after the method name and what is the difference between these two function.
These are called "ref qualifiers" and allow you to overload a member function depending on the value category of *this
.
int& func1() &
means: this overload of func1
can be invoked on any instance of *this
which can be bound to an lvalue reference.
int func1() &&
means: this overload of func1
can be invoked on any instance of *this
which can be bound to an rvalue reference.
E.g.
foo f; f.func1(); // calls &-qualified version
foo{}.func1(); // calls &&-qualified version