Programming Practice: Multiple symbols with the same name

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?
Last edited on
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...).
Thanks for the advice.

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.
Forgive me, I thought it was "Log::Level" and "level". I would say that is a bad idea.
Ah, OK. Very well, I shall put an m in front of the member variable then. Thanks again both of you.
Topic archived. No new replies allowed.