c++ - 从另一个文件中的函数检查 header 中定义的值

标签 c++ function header boolean

我有一个头文件 (head.h),我在其中定义了 boolean 值:

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 以以下行开头,也无法识别 boolean 值“flag”:

#include "head.h"

...为什么?

最佳答案

我相信你把 #include "head.h" 放在 main.c 的顶部(在 #include "stdafx.h" 之前) >) 并且您使用预编译 header (至少这是我能够使用 Visual Studio 重现您的问题的方式)。 #include "stdafx.h" 应该始终放在第一位。

关于c++ - 从另一个文件中的函数检查 header 中定义的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6002579/

相关文章:

c++ - 以 C++03 为目标时,使用 std::basic_string<t> 作为连续缓冲区是否合理?

c - 如何在C中解决 "control may reach end of non-void function"?

php - 从 PHP 中的 URL 重定向

c++ - 如何创建特定大小的 unordered_map?

C++__LINE__宏的类型是什么

解析函数字符串时的 JavaScript eval() "syntax error"

C 程序 : Update unsigned char pointer array with function

javascript - 如何在 PhantomJS 脚本中将 customHeaders 作为系统参数传递?

jquery - 在粘性标题下添加半透明框

java - Java 中的“导入”与 C/C++ 中的 '#include'