some weird class/struct problem

Hi, im having problems understanding what i did wrong on line
int x = l.my_light.light_number();
Im getting this message from compiler
Error 1 error C2228: left of '.light_number' must have class/struct/union

but if i just move mouse over l. Visual Studio tells me this
expression preceding parentheses of apparent call must have (pointer-to-) function type


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
enum class Light{
	green = 1, orange, red
};

struct traffic_light{
	Light light;
	//.....
	int light_number() const { return int(light); }
};

struct A_LOT_OF_LIGHTS{
	Light my_light;
	//...
	//Light light___n;
};

bool light_is_red(const A_LOT_OF_LIGHTS& l){
	int x = l.my_light.light_number();     
        //...
}


Here its the same
1
2
3
4
5
6
int main(){
	traffic_light trafic;
	trafic.light = Light::green;
	int x = trafic.light.light_number();

}
Last edited on
Line 18: light_number() is a member of traffic_light, but my_light is of type Light which has no light_number function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
enum Light{
	green = 1, orange, red
};

struct traffic_light{
	Light light;
	//.....
	int light_number() const { return (int)light; }
};

struct A_LOT_OF_LIGHTS{
	traffic_light my_light;
	//...
	//Light light___n;
};

bool light_is_red(const A_LOT_OF_LIGHTS& l){	
	int x = l.my_light.light_number();     
        //...
    return true;        
}

Ohh :) Thank you very much man!!
Topic archived. No new replies allowed.