Desperado wrote:once again, more simply...
Code: Select all
//----------------------------------------------------------
MODUL1:
//============DESPERADO.H=======
#define PIECE_H
#include "piece.h"
//==============================
//----------------------------------------------------------
MODUL2:
//===========ANY_OTHER_MODUL.H==
#include "piece.h"
//==============================
//----------------------------------------------------------
STANDALONE HEADER:
//===========PIECE.H============
#ifndef PIECE_DEC
#define PIECE_DEC
extern const UI_08 c_val; //no definition
#endif
#ifdef PIECE_H
extern const UI_08 c_val = 0; //definition
#endif
//==============================
//----------------------------------------------------------
so pls marco, let me know the dubious tricks here (i simplified a little bit) ?
You should look up a C/C++ book to learn more about the right use
of header files and implementation files. The bad news is that many books
do not provide you with very much information about this topic.
I assume you are not very experienced with C/C++ programming.
Please do not be angry if some of my advices are boring.
- Every module (*.h header file or *.c, *.cpp implementation file) should
include the declarations of everything it needs, and that is also needed
in other modules, by including the right header files. In some rare cases
it is also allowed to repeat the declaration.
- Header files should not include any definition.
- Header files shall not contain any using namespace xxx, but this is not
the problem in your case.
- Header files should use include guards around them to avoid parsing
them again and again. Use
#ifndef HEADERNAME_H
#define HEADERNAME_H
...
#endif // HEADERNAME_H
- Implementation (definitions) of constants, variables and functions
should be placed in the c/cpp files. Do not forget to tell the compiler that
you need all modules.
- The C/C++ files should include the related header files.
In your case:
Code: Select all
//===========PIECE.H============
#ifndef PIECE_H
#define PIECE_H
#include "the_header_that_contains_UI_08.h"
extern const UI_08 c_val; // declaration
// other declarations of piece here.
#endif // PIECE_H
//==============================
//===========PIECE.CPP============
#include "piece.h"
#include "the_header_that_contains_UI_08.h" // optional but i would do it.
const UI_08 c_val = 0; // definition
// other definitions of piece here.
//==============================
//============DESPERADO.H=======
#ifndef DESPERADO_H
#define DESPERADO_H
#include "piece.h" // if needed
// other declarations of desperado here.
#endif // DESPERADO_H
//==============================
//============DESPERADO.CPP=======
#include "desperado.h"
#include "piece.h" // if needed
// other definitions of desperado here.
//==============================
//===========ANY_OTHER_MODUL.H==
#ifndef ANY_OTHER_MODUL_H
#define ANY_OTHER_MODUL_H
#include "piece.h" // if needed
#include "desperado.h" // if needed
// other declarations of any_other_module here.
#endif // ANY_OTHER_MODUL_H
//==============================
//===========ANY_OTHER_MODUL.CPP==
#include "any_other_module.h"
#include "piece.h" // if needed
#include "desperado.h" // if needed
// other definitions of any_other_module here.
//==============================
Hope that helps. It is important to have this code structure right. Do not
use dirty tricks with #defines around #includes and #ifdefs inside headers.
If you have restructured your code it is also easier to give you more help
since now you use a typical structure that everybody can understand.
Harald