object-orientation question
here is my problem.
in my program,there are 4 class:winmain,player,raycaster,lookuptable.
either player or raycaster will contain a lookuptable in them in order to access information stored in lookuptable,so what i did is
//class player
#include lookuptable
//class raycaster
#include lookuptable
and in winmain head file of both player n raycaster will be included.but when i try 2 compile it.it gives me a error saying type lookuptable redefinition.i image the reason for that is both player and raycaster has lookuptable in it,as a result in winmain,compiler will try to declare lookuptable twice.
can anyone tell me a solution 2 that plz?thx.
put this at the start of the lookuptable header:
#ifndef __LOOK_UP_TABLE_HEADER
#define __LOOK_UP_TABLE_HEADER
and this at the end:
#endif // __LOOK_UP_TABLE_HEADER
when the file is first encountered, it will see that __LOOK_UP_TABLE_HEADER hasn''t been defined, so it will include everything between the #ifndef and #endif. However, if the header is opened again, it will see that __LOOK_UP_TABLE_HEADER has already been defined (by the first include), and therefor it will skip the code as it is already available.
#ifndef __LOOK_UP_TABLE_HEADER
#define __LOOK_UP_TABLE_HEADER
and this at the end:
#endif // __LOOK_UP_TABLE_HEADER
when the file is first encountered, it will see that __LOOK_UP_TABLE_HEADER hasn''t been defined, so it will include everything between the #ifndef and #endif. However, if the header is opened again, it will see that __LOOK_UP_TABLE_HEADER has already been defined (by the first include), and therefor it will skip the code as it is already available.
or, if you are using VC++ you can put in the compiler command:
#pragma once
somewhere in each header
#pragma once
somewhere in each header
quote:Original post by Symphonic
or, if you are using VC++ you can put in the compiler command:
#pragma once
somewhere in each header
#pragma once is also implemented in GCC 3.4.0.
put
#ifndef SOMEHEADERDEFINITION
#define SOMEHEADERDEFINITION
#endif
for every header file you have. not just lookup table.
#ifndef SOMEHEADERDEFINITION
#define SOMEHEADERDEFINITION
#endif
for every header file you have. not just lookup table.
quote:Original post by MENTAL
#ifndef __LOOK_UP_TABLE_HEADER
#define __LOOK_UP_TABLE_HEADER
You might want to stay away from defines or identifiers starting with double underscores, those are used by the compiler for internal names (as are names starting with a single underscore and a capital letter). Chances are no compiler uses __LOOK_UP_TABLE_HEADER, but if you use heaps of these you might at some point run into some weird, hard to find bugs.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement