【问题标题】:After defining a function in another file, visual studio does not recognize the function在另一个文件中定义函数后,Visual Studio 无法识别该函数
【发布时间】:2019-07-17 01:20:41
【问题描述】:

我正在创建具有许多页面(拆分为文件)的 Windows 控制台应用程序。我在执行程序时遇到问题,Visual Studio 抛出'startpage' identifier not found 错误(startpage 是函数,文件名是 startpage.h)

我尝试过使用: external int startpage();int startpage();。 我也尝试过只更改函数名称(因此文件和函数不使用相同的名称)。

我不知道为什么会这样。其他具有不同功能的文件正在工作。文件“startpage.h”使用了其他文件中定义的两个函数,它们不会引发任何错误。

#include "include/startpage.h"
#include <iostream>
#include <conio.h>
#include "include/concol.h"
#include "pch.h"
#include <iostream>
using namespace std;


int main()
{
    startpage(); 
}

```

这是错误:

Error code: C3861: 'startpage' identifier not found

【问题讨论】:

  • 如果您发布 startpage.h 的内容会有所帮助
  • #include "pch.h" 移至顶部。编译器会忽略包含预编译头文件之上的所有内容。
  • @IgorTandetnik 等等,这是真的吗?我的意思是我相信你我只是从来不知道这一点。你有一个很好的来源吗,我发现的都是this +2 answer
  • 是的,他是对的。 Visual Studio 会忽略 #include "pch.h" 以上的所有行或任何预编译头的名称。
  • 这里是文档的链接:docs.microsoft.com/en-us/cpp/build/reference/… 编译器将 .h 文件之前出现的所有代码视为预编译。它跳到与 .h 文件关联的 #include 指令之外,使用 .pch 文件中包含的代码,然后编译文件名之后的所有代码。

标签: c++ visual-studio


【解决方案1】:

将#include "pch.h" 移到顶部。编译器会忽略包含预编译头文件之外的所有内容。 ——伊戈尔·坦德尼克

这行得通! 非常感谢你们!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-20
    • 1970-01-01
    • 2021-06-18
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-21
    相关资源
    最近更新 更多