Enumerators vs Magic no.s

This is a discussion on Enumerators vs Magic no.s within the C++ Programming forums, part of the General Programming Boards category; I understand that it is not is good idea to use magic no.s ..but just take a look at the ...

Enumerators vs Magic no.s

I understand that it is not is good idea to use magic no.s ..but just take a look at the situation..
I need to describe a token..
A

Code:

int type[5]

would be sufficient for containing all the data..whether it is a number...or an operator....what type of operator...no of operands...etc etc....but it would scatter seemingly meaningless

Code:

if((x[0]==3)&&(x[2]!=0)) {;}

^ like statements through the whole code..
So, is it a better Idea to use 4 or 5 different enumerators?..
&& Also ..is there a hidden difference in performance..?..although I know that enums are basically numbers...still there could be something..!

Manasij Mukherjee | gcc-4.9.2 @Arch Linux Slow and Steady wins the race... if and only if :1.None of the other participants are fast and steady.
2.The fast and unsteady suddenly falls asleep while running !

Manasij Mukherjee | gcc-4.9.2 @Arch Linux Slow and Steady wins the race... if and only if :1.None of the other participants are fast and steady.
2.The fast and unsteady suddenly falls asleep while running !

..I know very well what classes and structures are..but what difference does using them here make?
Placing an object of

Code:

class Type
{
int n;
int n_o;
int pre;
//&& some more ints..
};

inside the token class..
brings the same problem with magic no.s...as with arrays....only somewhat better in specifying where to get what data...but the data is still in numbers...
Is there a better way to use them here?

Manasij Mukherjee | gcc-4.9.2 @Arch Linux Slow and Steady wins the race... if and only if :1.None of the other participants are fast and steady.
2.The fast and unsteady suddenly falls asleep while running !

Manasij Mukherjee | gcc-4.9.2 @Arch Linux Slow and Steady wins the race... if and only if :1.None of the other participants are fast and steady.
2.The fast and unsteady suddenly falls asleep while running !

Why would each mathematical function have a corresponding number? Why wouldn't it have a name instead? (EDIT: And if we're saying "call the functions directly from the names", then maybe we're storing function objects.)

Manasij Mukherjee | gcc-4.9.2 @Arch Linux Slow and Steady wins the race... if and only if :1.None of the other participants are fast and steady.
2.The fast and unsteady suddenly falls asleep while running !

Manasij Mukherjee | gcc-4.9.2 @Arch Linux Slow and Steady wins the race... if and only if :1.None of the other participants are fast and steady.
2.The fast and unsteady suddenly falls asleep while running !

Well, I had thought that there was an overarching class above unary_function and binary_function in the <functional> header, but I guess not. Still you can run with those, especially if you have a majority of one or the other.

Either way, you can always roll your own with something like

Code:

struct Functor {
int no_of_arguments;
};

and then you inherit dozens of subclasses off of this one, each one with its own operator().

If you're still doing arithmetic from the other thread, then one advantage of the <functional> struct is that plus, multiply, etc., are already there for the taking.

For dynamic function objects, you can use std::function instead of having to derive from your own class.
Another option is to simply use a template to hold an arbitrary type which can accept the () syntax, which basically means it's a function, member function or a class/struct with an overloaded () operator. But this is trickier.