Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: Beginner
Oct 10, 2000

Casts in C++

Question:
Can I cast an unsigned integer to an enumerator? If so, could you provide an example?

Answer:
You can use static_cast to cast an int to an enumerator. However, it's your responsibility to ensure that the int is within the valid ranges of the enumeration. Otherwise, the results are undefined.

Here's an example:

enum Stat {good=0, bad=1};
Stat s;
s=static_cast < Stat > (0); // s=good


enum Stat {good, bad};
Stat s;
s = static_cast < stat > (0); // s = good
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap