Definition of constant within namespace in cpp file

后端 未结 3 1407
青春惊慌失措
青春惊慌失措 2021-01-15 01:22

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         


        
3条回答
  •  时光取名叫无心
    2021-01-15 02:08

    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.

提交回复
热议问题