In C#, there is a nice syntax sugar for fields with getter and setter. Moreover, I like the auto-implemented properties which allow me to write
public Foo fo
You probably know that but I would simply 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, uses no clever tricks and it gets the job done!
The issue though is that some people don't like to prefix their private fields with an underscore and so they can't really use this approach, but fortunately for these who do, it's really straightforward. :)
The get and set prefixes doesn't add clarity to your API but making them more verbose and the reason I don't think they add useful information is because when someone needs to use an API if the API makes sense she will probably realize what it does without the prefixes.
One more thing, it's easy to grasp that these are properties because name isn't a verb.
Worst case scenario, if the APIs are consistent and the person didn't realize that name() is an accessor and name(value) is a mutator then she will only have to look it up once in the documentation to understand the pattern.
As much as I love C# I don't think C++ needs properties at all!