Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ - Performance when declaring enum outside or in class?

Tags:

c++

I have a pretty concrete question; Is there any difference in the performance when declaring an enum outside a class and when declaring an enum within the class? Thanks!


1 Answers

No, there is no performance difference.

Any enum or enum class declared within class scope has it's name bounded to the class' name (in the sense that the name of a class is also a namespace); and access checking is performed for its use.

The only real difference here is the access checking, otherwise, the namespace point, is not an issue, because every name in C++ is decared within some namespace (whether global or not).

There is no performance implication.

like image 60
WhiZTiM Avatar answered Dec 20 '25 14:12

WhiZTiM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!