I\'ve approached this strange ( for me ) effect in VS 2010. Can anyone smart shed some light on it please.
//Header.h
#include
namespace MySpa
You are missing "namespace" in your using. It should be like this:
#include "Header.h"
using namespace MySpace;
const std::string SOME_CONST_STRING = "CONST_STRING_VALUE";
You can alternatively write:
const std::string MySpace::SOME_CONST_STRING = "CONST_STRING_VALUE";
That name is declared inside MySpace
so you have to refer to it as such.
The whole point of namespaces is that names in a particular namespace are independent of names outside that namespace. A program could have both a MySpace::SOME_CONST_STRING
and a global ::SOME_CONST_STRING
, and these are two completely unrelated symbols. It would be wrong for the linker to use a definition of one to satisfy a reference to the other.
When you define a variable, you have to define it in the namespace where you want it to be.