ProgrammingVery hardProduct-company placement · C++

What is printed?

What is printed?
struct S {
    void f() &  { cout << "L"; }
    void f() && { cout << "R"; }
};
int main() {
    S s;
    s.f();
    S().f();
    std::move(s).f();
}
  1. A. LRR
  2. B. LLL
  3. C. LRL
  4. D. RRR

Correct answer: A. LRR

Ref-qualifiers overload member functions on the value category of the object: a named object is an lvalue (&), while a temporary and std::move(s) are rvalues (&&).

More OOP with C++ and Java questions

Exams that ask this topic