Variable existence checking before preprocess?

Apr 2, 2016 at 6:12am
Hi, i'm triying to create a define to call a struct function, but i't give me undefined reference of the function that i call.
For example:

#define CallFunction(a,b) a.b();

struct ocean_st{
void bake(){}
void setAmplitude(){}
};
int main(){
ocean_st Ocean;
CallFunction(Ocean,bake);
return 0;
}
Output: Undefined reference to bake.

Someone helpme? :D
Last edited on Apr 2, 2016 at 6:08pm
Apr 2, 2016 at 6:46am
"Undefined reference" normally means the linker can't find the function definition. Is this you real code? You shouldn't be getting this error because bake() is obviously being defined. Instead you should have got an error because you used -> and not . when calling the function.
Last edited on Apr 2, 2016 at 6:48am
Apr 2, 2016 at 6:12pm
Is not my real code. I didn't see the "->", i changed it to "." but the output is same.
If i test this code in windows the program work :/
(in linux tested with gnuc++11 and c++11)
Last edited on Apr 2, 2016 at 6:14pm
Topic archived. No new replies allowed.