I'm working on a FreeRTOS project, and I'd greatly like to take advantage of C++ where possible. I'm currently trying to create and use a pointer to a member function, so that I can pass the pointer as an argument in a FreeRTOS call.
The compiler is giving me errors for my code in the function call...can someone tell me what I'm doing wrong?
A pointer to a member function is a special kind of pointer that can't be used without an object of the correct type (I believe it's more of an offset than an address). If you need to pass a regular function pointer then you need to use a static function of the class (or a function outside of a class).
// we are defining a function pointer what we later on can set
// static function in a class would mean that the function has a structure to it
// instead of working more like a inline ( macro, replaced with compiled ),
// it works exactly like function would.
cout << "hello world" << endl;
// here we are setting a function pointer, we can do it anywhere, doesn't have to
// be class construction function. we can do it in main() as well.
myFunction = StaticClassFunction();
and we get the output:
or maybe you meant a virtual function?
I'm little confused cause of your code, it looks like a c++ but it isn't quite.
One important thing to remember. Class functions do not actually exist unless they are marked as static. Class functions are like inline functions, they will be replace with the code with in the function on compile time.
You can't also define anything in a class unless it's in the function or unless its a virtual.
I won't go into them cause I feel it's not what you want.
Fadey: I'm not committed to my original approach; as I mentioned in my first post, I'm just trying to use some C++ features for this FreeRTOS application. Frequently I'll need to furnish function addresses to system calls (as callbacks, etc). and I was hoping I could use an object function for this, but I'm starting to understand that I can't do that.
Hi poteto - thanks for the link. That does clarify what I can and cannot do. Unfortunately, I can't get the wrapper function technique to compile. I may send a message to the author, as there appears to be at least one error in his code.