You probably know this, but I would just do the following:
class Person { public: std::string name() { return _name; } void name(std::string value) { _name = value; } private: std::string _name; };
This approach is simple, does not use smart tricks, and it does its job!
The problem is that some people do not like the prefix of their private fields with underscores, and therefore they cannot use this approach, but, fortunately for those who do this, it is very simple. :)
The get and set prefixes do not add clarity to your API, but make them more detailed, and the reason why I do not think they add useful information is that when someone should use the API, if the API makes sense, she will probably understand what he is doing without prefixes.
One more thing, it's easy to understand that these are properties, because name not a verb.
In the worst case, if the APIs are consistent and the person does not understand that name() is an accessory and name(value) is a mutator, then she will have to look for it only once in the documentation to understand the pattern.
As much as I love C #, I don't think C ++ needs properties at all!
Eyal Solnik Mar 18 '16 at 22:46 2016-03-18 22:46
source share