Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in C++ , what's so special about "_MOVE_H"?

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,

like image 949
phunehehe Avatar asked Jul 27 '10 15:07

phunehehe


2 Answers

just run grep _MOVE_H in /usr/include/c++ on your machine

for me :

c++/4.5.0/bits/move.h:#ifndef _MOVE_H

As a rule of thumb, don't use things (really anything) prefixed by _ or __. It's reserved for internal usage. Use SOMETHING_MOVE_H (usually name of the company, ...).

I guess it's a new header used to add the move semantic to c++0x.

like image 168
Scharron Avatar answered Sep 24 '22 02:09

Scharron


Anything beginning with an underscore then capital letter is reserved to the implementation. (i.e. _M). I think in general you want to stay away from leading underscores.

like image 22
James Avatar answered Sep 23 '22 02:09

James