2014-01-26 33 views
3

我有我的代码如下声明:为什么我得到铛警告:没有以前的原型功能“差异”

//Central diff function, makes two function calls, O(h^2) 
REAL diff(const REAL h, const REAL x, REAL (*func)(const REAL)) 
{ 
    // diff = f(x + h) - f(x -h)/2h + O(h^2) 
    return ((*func)(x + h) - (*func)(x - h))/(2.0*h + REALSMALL); 
} 

这正好处于“utils.h”文件。当我编译一个测试使用它,它给了我:

clang++ -Weverything tests/utils.cpp -o tests/utils.o 
In file included from tests/utils.cpp:4: 
tests/../utils/utils.h:31:6: warning: no previous prototype for function 'diff' [-Wmissing-prototypes] 
REAL diff(const REAL h, const REAL x, REAL (*func)(const REAL)) 

我在这里失踪?

回答

3

既然你定义(不声明)您在头功能,那么你应该让内联。变化:

REAL diff(const REAL h, const REAL x, REAL (*func)(const REAL)) 

到:

inline REAL diff(const REAL h, const REAL x, REAL (*func)(const REAL)) 

或者只是移动定义为一个.c文件,并只保留一个原型在头文件。

相关问题