大家好,我有这样的代码:宏卫不工作头
//a.h
#ifndef SB
#define SB
namespace A{ int a = 10; int b = 10;}
#endif
但是,如果我进口的a.cpp文件啊,编译器会抱怨:
error LNK2005: "int A::a" ([email protected]@@3HA) already defined in a.obj
它看起来像编译器将.h文件和.cpp文件结合在一起,没有显式的“导入”语句。但对于我来说,在宏观卫士定义的情况下会发生这种情况。
我使用Visual C++
解决方案很好,但我认为这个问题最好由@James – 2011-07-27 19:13:29
确定+1不仅解决方案出现在问题上,而且问题的原因很明显。 – 2011-09-08 19:17:28