Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ header guards won't compile

Can't get any code using header guards to compile in vs 2010. For example:

#ifndef SIMPLE.H
#define SIMPLE.H

#include <iostream>

class Place {
private:
int m_xplace;
int m_yplace;
Place(){}
public:
Place(int x, int y) : m_xplace(x), m_yplace(y) {}
void Move(int x, int y);
void set_place(int x, int y) {m_xplace = x, m_yplace = y;}
int get_place_x() {return m_xplace;}
int get_place_y() {return m_yplace;}
};
#endif

I get this output from compiler:

1>------ Build started: Project: 1, Configuration: Release Win32 ------
1>e:\projects\1\1\simple.h(1): warning C4067: unexpected tokens following preprocessor     directive - expected a newline
1>e:\projects\1\1\simple.h(2): error C2008: '.' : unexpected in macro definition
1>e:\projects\1\1\simple.h(1): warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>e:\projects\1\1\simple.h(2): error C2008: '.' : unexpected in macro definition
========== 
Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Am i missing something obvious here? I'm quite sure i have the syntax correct. Thanks.

like image 376
Daniel Gratz Avatar asked Oct 23 '11 18:10

Daniel Gratz


1 Answers

You can't use . in the identifier.

Try this instead:

#ifndef SIMPLE_H
#define SIMPLE_H
like image 175
Mysticial Avatar answered Sep 27 '22 23:09

Mysticial