How can I avoid the LNK2005 linker error for variables defined in a header file?
问题 I have 3 cpp files that look like this #include "Variables.h" void AppMain() { //Stuff... } They all use the same variables inside them so they have the same headers but I get stuff like this 1>OnTimer.obj : error LNK2005: "int slider" (?slider@@3HA) already defined in AppMain.obj Why is that? 回答1: Keep in mind that a #include is roughly like cutting and pasting the included file inside the source file that includes it (this is a rough analogy, but you get the point). That means if you have: