#define __RESOURCE_H__

Apr 10, 2014 at 4:20pm
Hi all,
I'm a c++ beginner (coming from java) and I'm struggling to understand what the directive "#define __RESOURCE_H__" in the code below does.

I understand this could sound like a silly question, but I can't find any other reference to __RESOURCES_H__ in all the rest of the program sources and I don't understand the need of it.

Thanks in advance for your help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#if !defined(__RESOURCES_H__)
#define __RESOURCES_H__

//To be reviewed based on game dynamics
#define MAX_SYMBOL_TYPES   9

#include "Iw2D.h"
#include "Iw2DSceneGraph.h"

using namespace Iw2DSceneGraph;

/**
 * @class Resources
 *
 * @brief Resources class
 *
 * The that manages the lifetime of the following types of resources:
 * - Images
 * - Fonts
 * - Atlases
 */
class Resources
{
protected:
    CIw2DImage*     Gem;
    CIw2DImage*     MenuBG;
    CIw2DImage*     GameBG;
    CIw2DImage*     MenuButton;
    CIw2DImage*     Placard;
    CIw2DImage*     PauseIcon;
    CIw2DImage*     PlayButton;
    CIw2DFont*      Font;

public:
    CIw2DImage*     getGem()                    { return Gem; }
    CIw2DImage*     getMenuBG()                 { return MenuBG; }
    CIw2DImage*     getGameBG()                 { return GameBG; }
    CIw2DImage*     getMenuButton()             { return MenuButton; }
    CIw2DImage*     getPlacard()                { return Placard; }
    CIw2DImage*     getPlayButton()             { return PlayButton; }
    CIw2DImage*     getPauseIcon()              { return PauseIcon; }
    CIw2DFont*      getFont()                   { return Font; }

public:
    Resources();
    ~Resources();
};

extern Resources* g_pResources;

#endif  // __RESOURCES_H__ 
Apr 10, 2014 at 4:23pm
It's part of an inclusion guard - look at the line immediately before it and think about what happens if this file is included twice or more.

http://en.wikipedia.org/wiki/Include_guard

The C/C++ header and source file system is widely agreed to be bad, and currently the C++ standards committee is working toward a new Modules system that will be more like other languages you are familiar with. However, headers will remain for many years.
Last edited on Apr 10, 2014 at 4:23pm
Apr 10, 2014 at 4:33pm
wow, amazing. Multiple inclusion avoidance has to be manually managed! That's absolutely clear now.

Very valuable answer, you have saved me from a big headache :-)

Thank you a lot, very much appreciated.

Cheers
Topic archived. No new replies allowed.