我有以下3个文件(1间*的.cpp和2 * .HPP):如何从C++中的另一个头文件调用一个函数?
主程序文件:
// test.cpp
#include<iostream>
#include"first_func.hpp"
#include"sec_func.hpp"
int main()
{
double x;
x = 2.3;
std::cout << sec_func(x) << std::endl;
}
- 的first_func.hpp头:
// first_func.hpp
...
double first_func(double x, y, x)
{
return x + y + x;
}
- sec_func.hpp标题:
// sec_func.hpp
...
double sec_func(double x)
{
double a, b, c;
a = 3.4;
b = 3.3;
c = 2.5;
return first_func(a,b,c) + x;
}
如何正确调用sec_func.hpp文件中的first_func?
你是否在头本身实现了函数?如果是,那很糟糕。在头文件中有函数声明并在'.cpp'文件中实现它们。在希望使用这些函数的地方添加标题,并记住构建** all **源文件。虽然这不是功能模板的情况,这不是这里的情况。 – Mahesh 2012-07-22 18:12:41