Beginer C++ Error (how do read an enum in a struct)
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
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
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
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement