I have two nested classes named Level and OStream. The OStream class has a member of type Level:
1 2 3 4 5 6
class Log {
class Level { ... };
class OStream { ... public: Log::Level Level; ... };
};
As you can see due to a lack of imagination, both the variable and the class have the same name. Obviously this works, but would it be considered to be bad programming practice? Opinions, people?
In general, C++ developers like to prefix m_XXX or mXXX to indicate data members in a C++ class. I think this is good convention as sometimes the whole source code for a C++ class can span multiple pages and we get lost pretty quickly. A naming convention for data members make it easy from a maintenance point of view.
In C++, Level and level are different identifiers--they are not named the same. It's commonplace to see variables named like that. Some also adopt internal coding standards that specify naming conventions (such as mLevel for a member, etc...).
I know that they are different identifiers, but I thought it might be asking for trouble to give them the same name, since you have to remember to use "Log::Level" when the variable "Level" is in scope.