Reputation: 59
I have a header that has
typedef double func(double)
and a function declaration in a header called
double function(func f);
This is defined to do something in a corresponding .C file. So, to access this I have a file main.C that contains
#include"necessaryheader.h"
double f(double x){
return 1.0;
}
int main(){
func f;
double x = function(f);
std::cout << x << std::endl;
}
But when I attempt to compile this it throws an error
undefined reference to `function(double (*)(double))'
Why is this, is that not exactly the type that 'function(func f)' takes as a parameter? A better question is how do I make the types match?
Upvotes: 0
Views: 257
Reputation: 595961
typedef double func(double)
Should be
typedef double (*func)(double);
And make sure you are linking to a source file that contains the actual implementation of function()
.
And you need to get rid of the func f;
declaration in main()
.
Upvotes: 1