M
michael
Hi All,
I have the following:
------------ file constants.h---------
#ifndef constants_
#define constants_
const int FOO = 1;
const int BAR = 2;
char* NAME = "something";
const int ARGCOUNT = 2;
#endif
----------- file other.h -------------
#ifndef other_
#define other_
#include "Constants.h"
class Other {
public:
void crap();
};
#endif
----------- file other.cpp ----------
#include "Other.h"
void Other::crap(){
//stuff to do stuff
}
---------- file crap.cpp -----------
#include <iostream>
#include "constants.h"
#include "other.h"
using namespace std;
void doStuff(char* arg){
cout << "arg was " << arg << endl;
}
int main(int argc, char* argv[]){
if(argc < ARGCOUNT)
doStuff(NAME);
else
doStuff(argv[1]);
}
------------------------------------
When I compile, the compiler complains that I have 'multiple definition of
_NAME'
It has no problem with the other variables I have defined in Constants.h, so
why the problem with NAME?
It seems to be something to do with the char*, but I can't figure out what
or why.....
Thanks for your help
Michael
I have the following:
------------ file constants.h---------
#ifndef constants_
#define constants_
const int FOO = 1;
const int BAR = 2;
char* NAME = "something";
const int ARGCOUNT = 2;
#endif
----------- file other.h -------------
#ifndef other_
#define other_
#include "Constants.h"
class Other {
public:
void crap();
};
#endif
----------- file other.cpp ----------
#include "Other.h"
void Other::crap(){
//stuff to do stuff
}
---------- file crap.cpp -----------
#include <iostream>
#include "constants.h"
#include "other.h"
using namespace std;
void doStuff(char* arg){
cout << "arg was " << arg << endl;
}
int main(int argc, char* argv[]){
if(argc < ARGCOUNT)
doStuff(NAME);
else
doStuff(argv[1]);
}
------------------------------------
When I compile, the compiler complains that I have 'multiple definition of
_NAME'
It has no problem with the other variables I have defined in Constants.h, so
why the problem with NAME?
It seems to be something to do with the char*, but I can't figure out what
or why.....
Thanks for your help
Michael