Hi everyone.
I've created a class with an enum type in it as one of the class members. It only has two elements. Ascii and Unicode. Assigning a value to it is no problem, I just do...
m_type = Ascii;
// or...
m_type = Unicode;
But for some reason I can't use it in an if statement ??? So how am I supposed to find out what it is? When I do the following, when I compile I just get an error saying m_type is an undeclared variable
if(m_type == Unicode)
{
.....
}
Any ideas?
EDIT: Is it something to do with using enums in classes?
Lewis
This works for me. Do I understand the problem?
class a
{
enum code_type
{
ascii,
unicode
}
declare SetType(code_type type);
declare GetType(), code_type;
code_type m_type;
}
a::SetType(code_type type)
{
m_type = type;
}
a::GetType()
{
return m_type;
}
sub main()
{
a myClass;
OpenConsole();
myClass.SetType(ascii);
if (myClass.GetType() == ascii)
{
print("ascii");
}
else
{
print("nope");
}
while GetKey() == "";
CloseConsole();
}
Thanks a lot bruce. You know what, yours does work, mine does not because i declared the enum name as the variable name for some reason. However doing it like that doesnt cause the parser to spit an error when i assign a value, only when checking it in the if statement, which is what threw me.
Lewis
Enumerations aren't scoped. So there is no reason to have them in a class definition, although it won't hurt anything ;)