0

I'm using the BOOST_ENUM macro and trying to write a switch statement based on a variable of the enum type I created. I get the error message that "expression must have integral or enum type"

Is there any way to use Boost enums and switch statements together?

I've seen This link, but it says to use boost::native_value, and I get the message that the Boost namespace has no native_value member. I couldn't figure out if I'm supposed to be including an extra header files for it.

Any ideas?

Example code:

BOOST_ENUM(Direction, 
(Forward)
(Backward)
)
Direction response = Direction::Forward;
switch (response)
        {
case Direction::Forward :
      return; 
    break;
4
  • 1
    What does, 'I couldn't get to work' mean? What exactly happened? What error message did you get?
    – RedX
    Commented Jun 11, 2013 at 11:15
  • Added error message above
    – Meir
    Commented Jun 11, 2013 at 11:20
  • 1
    Is there a simple code example you can add to your question?
    – PeskyGnat
    Commented Jun 11, 2013 at 11:20
  • You keep changing your code. Don't do that. Which one do you have in your source file? 'Action' or 'Direction' '::Forward'?
    – RedX
    Commented Jun 11, 2013 at 13:50

1 Answer 1

2

You can't switch on a Direction object, try using switch (response.index()).

Naturally you also need to use Direction::Forward, not Action::Forward, but that may not even cause a compile error, depending how BOOST_ENUM is written.

You could also consider using a C++11 enum type:

enum class Direction { FORWARD, BACKWARD };
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.