I've approached this strange ( for me ) effect in VS 2010. Can anyone smart shed some light on it please.
//Header.h
#include <string>
namespace MySpace {
extern const std::string SOME_CONST_STRING;
}
//Implementation.cpp
#include "Header.h"
using namespace MySpace;
const std::string SOME_CONST_STRING = "CONST_STRING_VALUE";
This causes linker to output error LNK2001: unresolved external symbol const MySpace::SOME_CONST_STRING.
However when I change Implementation.cpp like this:
//Implementation.cpp
#include "Header.h"
namespace MySpace {
const std::string SOME_CONST_STRING = "CONST_STRING_VALUE";
}
the code builds OK.
Is it good example for prefering defining of namespace in cpp file rather than using it ?