Does it make sense to provide non-const reference getter

前端 未结 9 924
滥情空心
滥情空心 2020-12-16 23:58

Sometimes I need to expose some of the class members. For example in the following example class Mechanic may need direct access to Engine componen

9条回答
  •  忘掉有多难
    2020-12-17 00:26

    Instead of thinking about exposing private members of a class think more along the lines of calling methods on those classes. I read an interesting Java article, Why Getter and Setter Methods are Evil, which applies just as much to C++ as it does to Java.

提交回复
热议问题