[solved]annoying c++ issue.

I know this is javagaming.org but would one of you be able to help me with this annoying issue.
I am trying to use a namespace from one class in another class ive defined it within a header

namespace a { int d; };

this is defined within source two as

namespace a {
int d = 5;
};

however I get duplicate definitions.

When I remove the int d from the namespace it dosnt work.
its probably a simple mistake if someone could help with it.

You could try removing the int part in source two, that might work, but i am not sure because I haven’t used C++ in a while

In the header for source one, change to

namespace a { extern int d; };

In C++ “int d” is actually a definition not a declaration even though you don’t give it a value (it gets undefined value). Saying extern tells it just to declare and it will be defined (i.e. the memory allocated) elsewhere - in source two in this case.

Ahh thanks , I remember reading that you needed extern somehwhere.