Pointer to C++ function
Is there a way to pass to a C function a pointer to C++ function?
This is the C function
@int wiringPiISR (int pin, int edgeType, void (*function)(void)) ;@
My C++ functiin is this:
I can create a pointer to C++ function but the pointer is not valid for a C function.
@ funptr ptr;
Hi, if you make OnData() static you can do it.
I know but if I declare as static the function I can't use non static objects as qvector or QDateTime, declared in the class...
You could create static copies of your qvector and QDateTime objects as well.
The object has an own QVector, I have to append data to it. Is there a way?
No you cannot pass a pointer-to-non-static-member function, because its type is different. See http://www.parashift.com/c++-faq/fnptr-vs-memfnptr-types.html
- Your C function accepts pointers of type void (*)(void), but
- Your member function's type is void (QThlpt::*)(void)
If your compiler supports C++11, you can use std::bind() or a lambda to create a function of type void (*)(void) that modifies your C++ object. Then, you can pass this function to wiringPiISR()
Solved modifing the exteran c code by passing to it a pointer to my object and a pojnter to my function.
[quote author="JKSH" date="1412506264"]
If your compiler supports C++11, you can use std::bind() or a lambda to create a function of type void (*)(void) that modifies your C++ object. Then, you can pass this function to wiringPiISR()[/quote]
Could you give us an example of implementation?