Jump to content
  • Advertisement
Sign in to follow this  
Nahrix

Array of enumerations

This topic is 4899 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm not sure how to create an array of enumerations. I've tried using a vector of enumerations instead, but the push_back function doesn't seem to work with them.

Share this post


Link to post
Share on other sites
Advertisement
Try using a typedef.

Ex..


typedef enum Blah
{
ONE,
TWO,
THREE,
FOUR
} type_blah;

type_blah *foo;

foo = new Blah[x];





I have personally never done it, but it might work.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
just curious, what possible use could you have on an array of enums?

Share this post


Link to post
Share on other sites
Quote:
Original post by Nahrix
I'm not sure how to create an array of enumerations. I've tried using a vector of enumerations instead, but the push_back function doesn't seem to work with them.


Please show your code.

Share this post


Link to post
Share on other sites
In response to Gibson, you only need to typedef an enumeration in C. In C++, which he's using since he's trying to get a vector to work, enum's don't require the whole name "enum foo bar" each type to declare a new one. It works like how classes and structs are in C++. "enum foo; foo bar;"

Share this post


Link to post
Share on other sites
Thanks guys, but I've found the solution myself. Sorry I haven't responded; I went to bed, and had to work today.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What is the solution? I am going to be using a vector of enumerations myself.. and I am wondering if I should just use a vector of ints if using enumerations is too much of a pain.

Share this post


Link to post
Share on other sites
Don't see why it would be a pain

enum enumname {name1, name2....namen};

vector<enumname> vecname;

Would limit the valuse you could place in your vector...seems like a pretty reasonable idea..:)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!