我有一个像这样的简单 .h 文件:
//test.h
int x = 12;
例如,如果我在其中包含此文件,main.cpp
链接functions.cpp
器将产生此错误,这是合理的:
error LNK2005: "int x" (?x@@3HA) already defined in functions.obj
但是当我改变变量定义时:
//test.h
const int x = 12;
链接器错误消失。方式?
我有一个像这样的简单 .h 文件:
//test.h
int x = 12;
例如,如果我在其中包含此文件,main.cpp
链接functions.cpp
器将产生此错误,这是合理的:
error LNK2005: "int x" (?x@@3HA) already defined in functions.obj
但是当我改变变量定义时:
//test.h
const int x = 12;
链接器错误消失。方式?