Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 5
    const B& A::getB(const size_t idx) const;is the right way, the more you can put your members const the better it is. Note you can also have a const and a non const version of your members Commented Jul 7, 2020 at 8:39
  • 1
    This post should be helping. It's also an item in Effective C++. Casting argument to const and cast away return value with const_cast is okay. Commented Jul 7, 2020 at 8:39
  • 5
    Having both const and not const overload is clean C++. Commented Jul 7, 2020 at 8:41
  • Does this answer your question? How do I remove code duplication between similar const and non-const member functions? Commented Jul 7, 2020 at 9:16