0

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.

0

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.