Enum not working

New to FreeBASIC? Post your questions here.
Post Reply
mrminecrafttnt
Posts: 131
Joined: Feb 11, 2013 12:23

Enum not working

Post by mrminecrafttnt »

Hello Folks,
i acctually not understand why this is not working, thanks!

Code: Select all

ENUM ProcessState
        Running 
        Stopped
        Shutdown
        Free
    end enum

type process
    dim as ubyte state
    declare constructor()
end type

constructor process
    process.state = ProcessState.Free
end constructor
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Enum not working

Post by BasicCoder2 »

error 209: Illegal non-static member access, found 'state' in 'process.state = ProcessState.Free

This version seems to compile ok so that is probably a clue?

Code: Select all

ENUM ProcessState
    Running
    Stopped
    Shutdown
    Free
end enum

type process
    dim as ubyte state
    declare constructor()
end type

constructor process
    state = ProcessState.Free
end constructor
mrminecrafttnt
Posts: 131
Joined: Feb 11, 2013 12:23

Re: Enum not working

Post by mrminecrafttnt »

Yeah but why this error?
Any fixes are welcome..
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Enum not working

Post by paul doe »

mrminecrafttnt wrote:Hello Folks,
Yeah but why this error?
The member is not static, thus you can either access it with the this qualifier, or not qualify it at all:

Code: Select all

ENUM ProcessState
        Running
        Stopped
        Shutdown
        Free
    end enum

type process
    dim as ubyte state
    declare constructor()
end type

constructor process
  '' Either one of these will work
  state = ProcessState.Free
  this.state = ProcessState.Free
end constructor
Haubitze
Posts: 44
Joined: May 20, 2016 8:42

Re: Enum not working

Post by Haubitze »

try this

Code: Select all

ENUM ProcessState_e
        Running
        Stopped
        Shutdown
        Free
    end enum

type process
    state as ProcessState_e
    declare constructor()
end type

constructor process
  this.state = ProcessState_e.Free
end constructor
im not sure if it will help but if im using an enum as an "state"-variable then i declare it like this.
Post Reply