static variables in namespace/classes

Hello,
is it true that if you have the following :

1
2
3
4
5
//Header file .. myNameSpace.h

namespace myNameSpace {
   static int iMyInt = 0;
};


and if you include that header into multiple files you'll get multiple variables ? Why ?

And is this the same for the classes, for instance if we have

class myClass {
public:
static int iMyInt = 0;
}


Thank you
And is it supported at all to initialize it with zero there ?

1
2
3
namespace myNameSpace {
   static int iMyInt = 0;
};


Or do I have to do like this :


1
2
3
namespace myNameSpace {
   static int iMyInt;
};


and after that initialize it in .cpp ?
It's no different from putting
1
2
3
namespace myNameSpace {
   static int iMyInt = 0;
};
in every source file.

Do you understand what including a header file does? It just copies all the code in the header file into the cpp file.
To add to that you can't initialize variables in a class. That's what constructors are for.
Yes, I have just read about that...

But if we set inclusion guards in the header, why it still keeps entering (copying all the code from the header) ?
Topic archived. No new replies allowed.