IonicWind Software

Aurora Compiler => General Discussion => Topic started by: Zen on December 22, 2006, 05:43:53 AM

Title: Enum Problems
Post by: Zen on December 22, 2006, 05:43:53 AM
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
Title: Re: Enum Problems
Post by: Bruce Peaslee on December 22, 2006, 08:40:55 AM
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();
}


Title: Re: Enum Problems
Post by: Zen on December 22, 2006, 08:51:48 AM
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
Title: Re: Enum Problems
Post by: Ionic Wind Support Team on December 22, 2006, 11:26:05 AM
Enumerations aren't scoped.  So there is no reason to have them in a class definition, although it won't hurt anything ;)