C++: Callback in class -
I have a little complex class.
I have a reference in this class:
Pvt: IETPPTP _ PIETAPI;
IEtApiPtr is defined in .tlh file:
_COM_SMARTPTR_TYPEDEF (IEtApi, __uuidof (IEtApi));
The name of "SetRawDataCB" in IEtApiPtr is zero
Virtual HRESULT __stdcall SetRawDataCB (/ * [in] * / long address, / * [in] * / Long user data, / * [out, retal] * / enum apiError * pRetVal) = 0;
I have defined a callback function in class:
zero CETAPI :: rodenti (rotaata and r, zero * userata) {/ something]
I now want to install callback using
_pIEtApi-> SetRawDataCB ((long) (__ int64) (& RawDataCB), 0 And results);
... The compiler tells me "Invalid C2276: Invalid Operation for the expression of a bound member job".
What did I do wrong here?
This does not work because rodentibi
is a member function that has a global function You can declare as RawDataCB
as a static job as the following code and it will work. Although you will not have access to this
indicator (i.e. no member variables) unless you add it as the parameter of RawDataCB
and possibly RawDataCB
There is a member function to gain access to private data of a member class. This function declaration can be updated as follows:
class CETAPI {static blank rodacci (Rodata and R, blank * userdata); };
Alternatively, you can pass an indicator on RawDataCB
as a member function pointer instead of function indicator. Member Function Pointers can be compromised in this manner, so you can pass just one object type RawDataCBType
to SetRawDataCB
.
typedef void (CETAPI :: * rodectacby type) (rodata, zero *); // member type indicator typeer rodatasibipty pmf = & amp; CETAPI :: RawDataCB; // Member Function pocetapiobject-> pmf (r, userData) to create and start an indicator; / / CETAPI
Call member function on type of object is a good article that talks about member pointers.
Comments
Post a Comment