2

What is the difference between marking a function const vs const& of a class?

For example:

class abc {
Private:
    std::string str;
Public:
    const std::string& foo(const int&) const&;
    const std::string& bar(const int&) const;
}

Is there any difference between them? When would you use one over the other?

  • You seldom need reference qualified methods. So stick to the normal `const` – bolov Oct 03 '20 at 04:56
  • 1
    See [Const reference qualifier on a member function](https://stackoverflow.com/questions/23011532/const-reference-qualifier-on-a-member-function). – dxiv Oct 03 '20 at 04:58
  • Thank You. I didn't know about ref-qualifiers. And I guess the question is wrong cause I mistook it for const reference. Is there anything else that I need to know regarding this? – Neelava Chatterjee Oct 03 '20 at 05:24
  • Also should I delete my question or how should I edit or improve it for others to refer? – Neelava Chatterjee Oct 03 '20 at 05:26

0 Answers0