enum - cant' compile

Hi,

I tried to use enum in followin way, but i can't compile it. In standart gcc it works. Can somebody help me? The error message "error: 'device' was not declared in this scope" really does not help. :frowning:

enum device = {on, off, idle};

void SetDevice(device dev)
{
	switch(dev)
	{
		case device::on:
			break;
	}
}

thanks for help

Can you please post a short but complete problem that illustrates the problem ?

case device::on:Is this how you refer to an element of an enum ?

enum device {on, off, idle};

without =

use

enum struct device {on, off, idle};

to enforce enum namespace

UKHeliBob:
Can you please post a short but complete problem that illustrates the problem ?

case device::on:

Is this how you refer to an element of an enum ?

The goal is to define global function, which has one parameter as enum. If you try to paste the source code in .ino file a you compile it, you become an error.

Interresting is, that it works properly, if you are using the device enum inside a body of any function. In Functions you can in the same way declare and switch/case this enum variable.

see answer #2

No the solution without "=" doesn't work too. Try to put the code in separated file and compile it.

with = it was a syntax error. now it is a problem of ino file processing