0

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

1 Answer 1

4

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);
Sign up to request clarification or add additional context in comments.

3 Comments

Make sure the enum is in a public section as well.
And when he invokes FilterOut::LightIn(), he'll need to qualify the enumerated constant, also: int main () { ...; fo.LightIn(Driver::yellow); ... }
@Robᵩ Thanks, added an example.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.