How do I remove code duplication between similar const and non-const member functions?

后端 未结 19 2115
天涯浪人
天涯浪人 2020-11-22 00:30

Let\'s say I have the following class X where I want to return access to an internal member:

class Z
{
    // details
};

class X
{
    std::vec         


        
19条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 01:03

    Typically, the member functions for which you need const and non-const versions are getters and setters. Most of the time they are one-liners so code duplication is not an issue.

提交回复
热议问题