Use Enum or #define ?

Posted by sub on Stack Overflow See other posts from Stack Overflow or by sub
Published on 2010-03-30T20:32:41Z Indexed on 2010/04/01 3:13 UTC
Read the original article Hit count: 162

Filed under:

I'm building a toy interpreter and I have implemented a token class which holds the token type and value.

The token type is usually an integer, but how should I abstract the int's?

What would be the better idea:

// #defines
#define T_NEWLINE 1;
#define T_STRING 2;
#define T_BLAH 3;

/**
 * Or...
 */

// enum
enum TokenTypes
{
   t_newline,
   t_string,
   t_blah
};

© Stack Overflow or respective owner

Related posts about c++