c++ - or'ing enums that are in namespaces -


i've learned putting enums in namespaces avoids compiling errors when 2 enums share 1 equaly named item.

namespace feeling {     enum e     {         happy = 1,         sad = 2,         blue = 4,         angry = 8,         mad = 16     }; } 

so can pass functions declared like

void howdoyoufeel(feeling::e feeling); 

but when trying or this:

howdoyoufeel(feeling::happy | feeling::blue); 

i error. best way handle this?

the question asks "the best methd", bit subjective. write e operator|(e left, e right) { return e(int(left)|int(right)); } these cases, make clear feeling::e has orthogonal encoding.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -