
[英]Function defined in the header and called from the cpp file error
[英]Checking a value defined in a header from a function in another file
我有一个头文件(head.h),在其中定义了布尔值:
bool flag = false;
在main.c中,我有一个函数:
void WINAPI function (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
if (flag == false)
{
//Some action
flag = true;
}
}
即使main.c以以下行开头,也无法识别布尔值“标志”:
#include "head.h"
...为什么?
我相信您将#include "head.h"
放在main.c
的顶部(在#include "stdafx.h"
之前),并且使用了预编译的头文件(至少这是我能够通过Visual Studio重现您的问题) 。 #include "stdafx.h"
应该始终排在第一位。
“不被认可”是什么意思? 说没有定义flag
是否编译失败?
否则,在您展示的代码中,存在一个从未设置过标志的小问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.