Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass enums by value or reference?

Tags:

c++

enums

My general rule is to pass by value for primitive types and pass by reference for objects (obviously const'd if need be). However, I'm not sure what route to take with enumerated types. I'd assume that pass by value is preferred since they are seemingly small, but I'd like to hear others thoughts.

like image 565
Anonymous Avatar asked Dec 02 '22 06:12

Anonymous


2 Answers

No other thoughts. An enum is just an integral value in a fancy dress (or suit, if you prefer). It has no internal structure and will travel in a register given a chance. If you'd pass an int by value, pass an enum that way, too.

like image 85
bmargulies Avatar answered Dec 23 '22 11:12

bmargulies


Enum have a underlying representation type which is an integer types. There are no more reasons (and no less) to pass them by reference that there are reasons to pass integer types by reference.

like image 45
AProgrammer Avatar answered Dec 23 '22 09:12

AProgrammer