Joerg Toellner
2003-07-16 09:49:59 UTC
Hi Group,
Dont know how to solve my problem with my little brain by myself. Maybe my
way is not the best at all and maybe not C++ style...but i don't no to do
better at the moment. So excuse my maybe horrible coding-style.
I have the following files:
a.cpp
b.cpp
b.h
in b.h are many declarations and function prototypes that have to be used in
a.cpp AND b.cpp. So i have to include b.h in both .cpp files.
As there are initialised variables in the .h files too, like:
char error_msgs[][100] = { "No error",
"I/O error",
"Too many fingers on
keyboard error",
"Out of this world error"
};
i decided to wrap the .h file with the lines:
#if !defined( _B_HFILE_INCLUDED_ )
#define _B_HFILE_INCLUDED_
... blah blah blah // The content of b.h
#endif
to prevent double inclusion of b.h and so the h file should only be
included once.
But although i do this, i get the compilation/linking error:
b.obj: char * error_msgs[][100] already defined in a.obj
Huh? I thought the #if/#endif construction will prevent this.
I really don't want to define all the hundreds of error message strings in
every .cpp file. :-( What do i wrong?
Any hint appreciated.
TIA
Joerg Toellner
Dont know how to solve my problem with my little brain by myself. Maybe my
way is not the best at all and maybe not C++ style...but i don't no to do
better at the moment. So excuse my maybe horrible coding-style.
I have the following files:
a.cpp
b.cpp
b.h
in b.h are many declarations and function prototypes that have to be used in
a.cpp AND b.cpp. So i have to include b.h in both .cpp files.
As there are initialised variables in the .h files too, like:
char error_msgs[][100] = { "No error",
"I/O error",
"Too many fingers on
keyboard error",
"Out of this world error"
};
i decided to wrap the .h file with the lines:
#if !defined( _B_HFILE_INCLUDED_ )
#define _B_HFILE_INCLUDED_
... blah blah blah // The content of b.h
#endif
to prevent double inclusion of b.h and so the h file should only be
included once.
But although i do this, i get the compilation/linking error:
b.obj: char * error_msgs[][100] already defined in a.obj
Huh? I thought the #if/#endif construction will prevent this.
I really don't want to define all the hundreds of error message strings in
every .cpp file. :-( What do i wrong?
Any hint appreciated.
TIA
Joerg Toellner