Question

Originally my code was:

#ifndef 2DO_H   
#define 2DO_H  
int ReadNumber();  
void WriteAnswer(int Nsumber1, int Number2);  
#endif

However I was getting an error #if[n]def expected an identifier. So I played around with it and realized that my error was in 2DO_H. When I changed my code to:

#ifndef DO_H   
#define DO_H  
int ReadNumber();  
void WriteAnswer(int Nsumber1, int Number2);  
#endif

It worked in the above case because I changed 2DO_H to DO_H. Why is it that when I have an extra number in front of the identifier, I get an error?

Was it helpful?

Solution

Because identifiers aren't allowed to start with a digit. This is covered in 2.11 Identifiers of the current C++ 11 standard, specifically the syntax section:

identifier:
    identifier-nondigit               # No digit allowed at front here.
    identifier identifier-nondigit    # Nor here.
    identifier digit                  # Nor here.

OTHER TIPS

#ifndef 2DO_H

Nah.

#ifndef TODO_H

instead. An identifier can't begin with a digit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top