Bruintje Beer wrote:
Quote:
I have an include file constants.h see below. Later I want to include
this header file in two c++ source files because they both need the
variables f1, f2 and f3. At link time I got an error that f1, f2 and
f3 are alread defined in one of the c++ source files. How can I
change my code so both c++ source files can have access to the fields
f1, f2 and f3.
John
>
#ifndef __CONSTANTS_H
#define __CONSTANTS_H
>
namespace demo
{
const char* f1 = "field_1";
const char* f2 = "field_2";
const char* f3 = "field_3";
}
>
#endif
Generally speaking, you probably want to make the pointers constant
as well:
const char* const f1 = ...
Try it. If that doesn't work, define them as arrays:
const char f1[] = ...
If *that* doesn't work, you can always declare them as extern and
define them in only one of your C++ files:
extern const char* const f1;
// in one of your C++ files:
extern const char* const f1 = "field_1";
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask