我在这里搜索了很多次,发现这个问题很多次了,但是作者通常没有提供一个代码示例,我今天遇到了这个问题,我不知道如何解决它。
其中一个错误列出了bool Init(?@@A_NA) already defined in Client.obj。下面是我为Client.cpp、Main.cpp和Main.h编写的部分代码。
Client.cpp
#include "stdafx.h"
#include "Main.h"
// the rest of the code doesn't have anything to do with this error..Main.h
#include "stdafx.h"
bool Init;
// the rest of the code doesn't have anything to do with this error..Main.cpp
#include "stdafx.h"
#include "Main.h"
int main()
{
Init = false;
return 0;
}发布于 2014-12-30 04:30:08
在#include "Main.h"中,您已经定义了bool Init;,所以每次包含Main.h时,都会重新定义Init。如果Init是静态的,
static bool Init;在这里,Init将有页面级别的作用域,您的代码应该可以正常工作。
或者更好的是,你让Init退出Math.h,
extern bool Init;然后在.cpp文件中定义它,这样您将有多个声明,但只有一个定义。
https://stackoverflow.com/questions/27699548
复制相似问题