Hi all,
I am attempting to wrap my brain around function pointers. I created two files, exeCallback.h and exeCallback.cpp. I am receiving the error: "expression must have (pointer-to-) function type". The error resides at:After reading that error, I edited the line that was giving me the error toCode:foo(2);.Code:exeCallback->foo(2);throws two new errors that are, expected an identifier and expected a type specifier. What am I not doing to get my basic callback library to work successfully?Code:exeCallback->foo(2);
exeCallback.h code:
exeCallback.cpp file code:Code:/* File: exeCallback.h Header file for exeCommand Library. */ #ifndef EXECALLBACK_H #define EXECALLBACK_H #include "mbed.h" #include <functional> #include <map> class exeCallback { public: exeCallback(); void my_int_func(int x); void (exeCallback::*foo)(int); private: }; #endif
Code:/* File: exeCallback.cpp Execute functions in other Sensor libraries/classes Constructor */ #include "mbed.h" #include "ConfigFile.h" #include "msExtensions.h" #include "cfExtensions.h" #include "exeCallback.h" exeCallback::exeCallback() { foo = &exeCallback::my_int_func; foo(2); } void exeCallback::my_int_func(int x) { printf( "%d\n", x ); }



LinkBack URL
About LinkBacks



