Sign in to follow this  
warp X

c++ enum question

Recommended Posts

Ok, this might sound silly, but I was just wondering, that are 'enum' constants static? I mean how could I really know...

Share this post


Link to post
Share on other sites
They are constants and reside within their namespace, which - if you didn't specify any other namespace - would be the global namespace.
All constants are static and can always be accessed.

#include <iostream>
enum { CONST_01, CONST_02 };
enum TSomeConst { CONST_03, CONST_04 };

namespace Constants {
enum { CONST_01, CONST_02 };
};

int main( void ) {
std::cout << CONST_02 << TSomeConst::CONST_03 << CONST_04 << Constants::CONST_01 << std::endl;
};

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this