0

I understand that RVO enables copy elision of, amongst others, temporaries and local variables, but what about data members ?

To focus the question, which of the following three options is the best way to write a const getter for a data member (given RVO and C++11)?

class Widget { /* some large user-defined class */ };

class C
{
public:
    const Widget& getWidget1() const { return w; }
    const Widget getWidget2() const { return w; }
    Widget getWidget3() const { return w; }

private:
    Widget w;
};
mr_T
  • 2,571
  • 3
  • 22
  • 39

0 Answers0