Hello. I'm having a problem using enum objects as non-type parameters in class templates. Consider the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
enum Team
{
Chelsea,
Real Madrid
};
template<class T>
class Player<Team t>
{
...
...
class definition
};
This code compiles without giving any sort of errors, but when I try to instantiate the class like this,
1 2 3
Player<Team::Chelsea>* player;
it gives me errors:
'Chelsea' : illegal qualified name in member declaration
'player' : undeclared identifier
syntax error : missing ')' before ';'
syntax error : missing '>' before ';'
whereas when I do this
1 2 3
Player<(Team)1>* player;
, it compiles successfully. i'm confused as to why this happens. Any suggestions would be helpful
I'm sorry. I had used an underscore previously. I did not type it here. And yes, I even tried qualifying the enum values within the enum scope, like this:
From my experience, the scope-resolution operator (::) isn't used with enumerations.
Just try: Player<Chelsea>* player;, instead of Player<Team::Chelsea>*player;.