在多个 cpp 文件中包含一个 h 文件

时间:2021-02-08 17:02:42

标签: c++ compiler-errors header-files function-definition multiple-definition-error

我目前正在处理一个项目,该项目包含多个 .cpp 文件使用的文件(generalFunctions.h 和 1x generalFunctions.cpp)。在这些文件中写着 #include "generalFunctions.h"

但是,我收到一个错误:函数定义为乘法。

有人可以帮我解决这个问题吗?

问候

1 个答案:

答案 0 :(得分:1)

必须从包含在多个编译单元中的头文件中排除函数定义,前提是函数未使用说明符 static 或 inline 声明。此外,您不得在其他 cpp 文件中包含 cpp 文件。