DEV Community

Discussion on: Let's try C++20 | using enum

Collapse
 
maresia profile image
Maresia

With auto complete features like using enum seem useless and problematic. I prefer to use the full name to avoid the name conflict that can occur as the code grows.
[from google translate]

Collapse
 
pgradot profile image
Pierre Gradot • Edited

Just like using namespace std; or using std::cout;, you should you use using enum EnumWithALongName; in a (very) limited scope to avoid conflicts.

From my experience, if everything function / type / constant is in a namespace, has a descriptive name, and you avoid wide scopes, you will almost run into troubles.

And I assume the C++ committee as the same point view since they added using enum xxx to C++20 ;)

Have you experienced some issues?

Collapse
 
maresia profile image
Maresia • Edited

Yes, it has occurred to me to use one function by mistake, imagining it to be another. The result was a code that behaved very strangely and I only noticed that it used the wrong function much later after spending a long time fighting with gdb. Since then I use this extensively and avoid using.

Thread Thread
 
pgradot profile image
Pierre Gradot

I understand your pain...