I have a C++ file like this
#ifndef _MOVE_H
#define _MOVE_H
class Move {
int x, y;
public:
Move(int initX = 0, int initY = 0) : x(initX), y(initY) {}
int getX() { return x; }
void setX(int newX) { x = newX; }
int getY() { return y; }
void setY(int newY) { y = newY; }
};
#endif
And to my amazement, all the code between #ifndef
and #endif
is simply ignored by the compiler (I swear that I am not defining _MOVE_H
anywhere else), and I have all kinds of errors about missing definitions. I was thinking that I did something wrong, but when I try to use another key (like _MOVE_Ha
, everything is back to normal. Does _MOVE_H
mean something special in C++ ?
I'm running Ubuntu 10.04, GCC 4.4.3, if that matters.
Thanks,
#pragma once
instead of#define
include guards... – Corrincorrina#pragma once
is a compiler extension and not supported by all compilers. Include guards are the only safe compiler independent means of preventing multiple inclusion. – Sofko#pragma once
saves the compiler from having to open and process the same guarded header over and over every compile. – Corrincorrina