0

I wrote

#ifndef Header1.h
#define Header1.h

class Complex
{
   [...]
};

#endif

in my project (Visual Studio 2010) and I get an Error C2008: '.' : unexpected in macro definition. I don't understand what the problem is with "Header1.h" or how to fix it.

Eutherpy
  • 4,471
  • 7
  • 40
  • 64
  • 2
    The error message is pretty clear... there's nothing we can do apart from restate it - you can't used `.` in a macro name. – JoeG Nov 05 '13 at 19:59
  • It wasn't intended in that tone. I'll edit it. Can't edit it, I'll delete it. – kfsone Nov 05 '13 at 20:15
  • The error message was indeed very clear, but I'm a beginner, and didn't know about the rule. – Eutherpy Nov 05 '13 at 20:17

4 Answers4

4

Don't use the . use an _ instead

#ifndef HEADER1_H
#define HEADER1_H

class Complex
{
   [...]
};

#endif
Montaldo
  • 863
  • 8
  • 16
2

You need to use an identifier here:

#ifndef Header1.h
        ^^^^^^^^^

and they can not include . in them, we can see this from the draft C++ standard section 16 Preprocessing directives paragraph 1 which includes the following grammar:

# ifdef identifier new-line groupopt
        ^^^^^^^^^^
# ifndef identifier new-line groupopt
         ^^^^^^^^^^

typically include guards are all caps and an underscores:

 #ifndef HEADER1_H
Community
  • 1
  • 1
Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
1

Macro names can't contain periods. Rename it to Header1 or Header1h.

As an aside, it's standard for most macros to be ALL_UPPERCASE.

Collin Dauphinee
  • 13,664
  • 1
  • 40
  • 71
1

A macro name should not contain a dot. You'd better use

#ifndef HEADER1_H
#define HEADER1_H

...

#endif
pvoosten
  • 3,247
  • 27
  • 43