Click here to Skip to main content
15,888,301 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

in C++ program when I have declared an Enum like this.

enum { infinity=-1 };

I am getting the below error

Expected an identifier

I am assigning the infinity to long variables in further lines of code like below

long x=infinity;

Could you please help me why I am getting Expected an Identifier error.

What I have tried:

I tried to declare infinite instead of infinity. but no luck.
Posted
Updated 27-Aug-19 21:50pm

1 solution

You forgot to add a name of enum.

Replace ths:
C++
enum { infinity=-1 }; 

with:
C++
enum name_of_enum_here { infinity=-1 }; 


See: Enumeration declaration - cppreference.com[^]
 
Share this answer
 
Comments
Stefan_Lang 29-Aug-19 4:08am    
Well spotted! Your eyes are better than mine...
Maciej Los 29-Aug-19 4:18am    
Thank you, Stefan.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900