Can't use enum from another class

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
Post Reply
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Can't use enum from another class

Post by Nash »

Code: Select all

class ClassA
{
    EMyEnum
    {
        THINGY_One,
        THINGY_Two,
    }

    EMyEnum e;
}

class ClassB
{
    // does not work
    ClassA.EMyEnum e;
}
 
Should be self explanatory.

The only way this will work is to declare EMyEnum in the global namespace. Not good...
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: Can't use enum from another class

Post by Arctangent »

I don't exactly see why you'd expect it to without ClassB inheriting from ClassA.
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: Can't use enum from another class

Post by Nash »

That's the only way? I can't do that, because in the real-world use case in my project, both classes are completely different (A is Inventory, B is Thinker)
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Can't use enum from another class

Post by Matt »

They can also be accessed as "ClassA.THINGY_One" even if it's a little cumbersome to type out each and every time.

(I wish I knew that before I put everything in the global namespace lol)
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: Can't use enum from another class

Post by Nash »

Matt wrote:They can also be accessed as "ClassA.THINGY_One" even if it's a little cumbersome to type out each and every time.

(I wish I knew that before I put everything in the global namespace lol)
They can be accessed, sure, but I want to create a variable of the Enum type on another class, and that's what's not working here.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Can't use enum from another class

Post by Graf Zahl »

Enum variables do not really work. Just use a simple int instead. This is all a result of the original type system where the enum implementation was broken beyond repair. I still haven't found the time and desire to fix it.
Post Reply

Return to “Closed Bugs [GZDoom]”