April 19, 2024, 06:18:25 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Enum Problems

Started by Zen, December 22, 2006, 05:43:53 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zen

December 22, 2006, 05:43:53 AM Last Edit: December 22, 2006, 05:53:27 AM by Zen
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

Bruce Peaslee

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();
}


Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Zen

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

Ionic Wind Support Team

Enumerations aren't scoped.  So there is no reason to have them in a class definition, although it won't hurt anything ;)
Ionic Wind Support Team