   namespaces and multiple .cpp files
  Do I still have to use extern on namespaces if I have a namespace in a header file? And use it in 2 or more .cpp files? If so what is the correct way to do so. I have tried to use extern in front of the namespace name and variable but it still doesn''t work?   //file FOO.h#ifndef FOO_H#define FOO_Hnamespace FOO{int x;};#endif//file FOO.CPP#include "foo.h"int ADD(void){return FOO::x + FOO::x;}//main.cpp#include "foo.h"int main(int argc, char *argv[]){cout << FOO::x;return 0;}
  I tried to compile this code and after fixing it a little bit (adding include iostream and using namespace std ) i got:bash-2.05b$ make  LINK:    foomain.o(.bss+0x4): multiple definition of `FOO::x''foo.o(.bss+0x0): first defined herecollect2: ld returned 1 exit statusmake: *** [default] Error 1So it means you need extern here, but in front of int x. Then you have to define the variable again (without extern) in the processing unit where it belogs. So the corrected code is://file FOO.h#ifndef FOO_H #define FOO_H namespace FOO{    extern int x;};#endif //file FOO.CPP#include "foo.h" int FOO::x;int ADD(void){    return FOO::x + FOO::x;}//main.cpp#include <iostream> #include "foo.h" using namespace std;int main(int argc, char *argv[]){    cout << FOO::x;    return 0;} darkoneRegistered Linux User #317188 ;  Thanks 