Please support our C++ advertiser: Programming Forums
Views: 1623 | Replies: 3
![]() |
Simplify my problem I put a short version of code here,
first header file:
cpp file:
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.
first header file:
namespace xxx{
class util{
public:
static int MAX_PATH ;
util();
static void init();
static void do(void);
}; //end class
int util::MAX_PATH ;
}cpp file:
namespace xxx{
util::util(){
init();
}
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.
http://www.parashift.com/c++-faq-lit...html#faq-10.11
Moral: don't put the definition in the header.
[edit]And do is a keyword.
Moral: don't put the definition in the header.
[edit]And do is a keyword.
High Plains Blogger #plains #lounge ## I, for one, welcome our new socialist overlords.
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
Thanks, actually i thought I used #ifndef so this would not be included more than
once.
for the do( ), i just use it to simplify code, more like doSomething( )
once.
for the do( ), i just use it to simplify code, more like doSomething( )
•
•
•
•
Originally Posted by Dave Sinkula
http://www.parashift.com/c++-faq-lit...html#faq-10.11
Moral: don't put the definition in the header.
[edit]And do is a keyword.
•
•
•
•
Originally Posted by alone2005
Thanks, actually i thought I used #ifndef so this would not be included more than once.
High Plains Blogger #plains #lounge ## I, for one, welcome our new socialist overlords.
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode