Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

CtrlAltDelete

Beginer C++ Error (how do read an enum in a struct)

This topic is 6938 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

Okey Ive had this problem long enough so im posting it up here in hopes that one of you can quickly spot my error. struct somestruct{ enum Value {TRUE, FALSE} }; void someFunction(somestruct *AStruct) { if(AStruct->Value == TRUE) //<-error TRUE is undefined DOTHIS } Thanks in advance, Chuck

Share this post


Link to post
Share on other sites
Advertisement
Anything you place inside a struct or class ends up in that class''s scope. Therefore you need tell the compiler which class to look for the identifier in using the scope operator. Your code should therefore be:

void someFunction(somestruct *AStruct)
{
if(AStruct->Value == somestruct::TRUE)
DOTHIS
}

You may also find that
if(AStruct->Value == AStruct.TRUE)
works also, but if so, that is just confusing

Share this post


Link to post
Share on other sites
enum Value {TRUE, FALSE}

is just a type definition - like

struct Structure
{
bool bRightOrWrong;
};

is just a type definition. To use the enum you have to declare/define a variable using this type:

somestruct::Value MyValueC;

MyValue=somestruct::TRUE;

Ok? You can''t store values inside of somestruct::Value - it is "just" a type.

Hope this helped,


Bjoern

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!