Aaron
Aaron

Reputation: 4480

Trying to pass in an enum from another class

I have two classes one the Driver and the other one called FilterOut. In Driver, I have an enum called lights that I passed in correctly into FilterOut as an int. I am having trouble figuring out how to do this as a enum.

The enum in my Driver class

enum lights{yellow, green, red, blue};

This worked for me.

void FilterOut::LightIn(int light)
  {
       switch(light);
  }

What I would like to do.

void FilterOut::LightIn(lights light)
  {
       switch(light);
  }

I tried this and several variations but have had no luck, any ideas? I have also tried to include an enum in FilterOut that is the same as the one in Driver and that has now worked either

Upvotes: 0

Views: 1799

Answers (1)

juanchopanza
juanchopanza

Reputation: 227418

If the enum is in the Driver class, then you have to qualify its name:

class FilterOut {
 public:
  void LightIn(Driver::lights light);
};

void FilterOut::LightIn(Driver::lights light)
{
   switch(light);
}

You also have to qualify the look-up scope when calling the function:

FilterOut f;
f.LightIn(Driver::red);

Upvotes: 4

Related Questions