Simplify my problem I put a short version of code here,
first header file:

namespace xxx{
class util{
	static int MAX_PATH ;
	static void init();
	static void do(void);
}; //end class
int util::MAX_PATH ;

cpp file:

namespace xxx{
void util::init(){
	MAX_PATH = 100;
void do(){
        //use MAX_PATH somewhere

my problem is I can compile them to generate .o file correctly, but whenever I link them
with other program, i got:
...multiple definition of MAX_PATH...

think hard but found no reason, anyone can help? thanks in advance.

Recommended Answers

All 3 Replies

Thanks, actually i thought I used #ifndef so this would not be included more than once.

Right -- per module. Each module then has its own copy and this upsets the linker.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.