C++:code::block 无法识别包含的 header

标签 c++ header compiler-errors include codeblocks

我在 C++ 中得到了以下代码:

in main():

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
cout << function(1) << endl;

return 0;
}

在我的源代码文件中:

#include <math.h>

int function(int number)
{
int value(number + 2);

return value;
}

在我名为“math.h”的标题中:

#ifndef MATH_H_INCLUDED
#define MATH_H_INCLUDED

int function(int number);

#endif // MATH_H_INCLUDED

当我尝试编译它时出现错误:“函数”未在此范围内声明

我哪里错了?

最佳答案

<math.h>是标准头文件,使用#include <math.h>使其优先于当前目录的标准头文件路径,除非您赋予当前目录优先级(例如,通过使用 -I 开关指定包含路径)。

如果您使用 #include "math.h"相反,编译器将首先搜索当前目录。或者,您可以将头文件重命名为不同于 math.h 的名称。 .

关于C++:code::block 无法识别包含的 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16308943/

相关文章:

ios - 在分组表中设置标题 View 时出现问题

java - 尝试在 android studio 中安装按钮时出现编译器错误

c++ - MSVC : what compiler switches affect the size of structs?

c# - Unity3d C++ 插件

c++ - 修改c++头文件后如何重新编译?

c# - 为什么调用此列表方法会返回不可访问错误?

.net - 使用 @Html.ActionLink() 时出错

c++ - 从 fortran 调用 c++ sub 时运行时中止

c++ - 在类中定义主函数

c++ - 通用对象包装器