
On Jan 18, 2012, at 8:40 AM, Johan Engelen wrote:
On 17-1-2012 22:14, Johan Engelen wrote:
Hi all, I am busy 'improving' a small part of the code to use an underscore for class members. I think this helps fight bugs when converting C functions to class methods. For example, a SPPath function may define a temporary variable 'curve', but that one will hide the class's own 'curve' variable (inherited from SPShape). Since the class hierarchy is quite long at places, this is not so easily spotted. So I think the _* stuff for members is really nice and clarifies code a lot.
However, now I read in our codestyle document:
- Underscore as first character of identifiers Please consider that the C++ standard reserves _* identifiers
[17.4.3.1.2]: "Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace".
Or did I misinterpret, and does it mean that ::_* is reserved, but JohanClass::_hello is perfectly fine?
Yes, you just hit on it.
General identifiers can not start with an underscore, but members of a class are as you noted.
_JohanClass::_hello would be bad, but JohanClass::_hello is fine.
Oh, and there could be a minor variation to consider. Some coders like to put the underscore at the end, not beginning. Given the existing prefixing all over our code, staying consistent might be good. But I did want to highlight the option.