CラッパーをC++で作成しようとしています。C++クラスメンバ関数からC構造体ポインタへ
しかし、クラス内の関数を構造体関数ポインタに変換することはできません。
myCallback関数は、オーバーライドする必要があるため、静的に使用しないでください。ここで
はサンプルコードです:ここでは
#include <iostream>
extern "C" {
typedef struct _client_config
{
void (*on_connect)(void *client, int result);
} client_config;
}
class Parent
{
public:
Parent() {};
~Parent() {};
virtual void myCallback(void* hello, int world) = 0;
};
class Child : public Parent
{
public:
Child() {};
~Child() {};
void myCallback(void* hello, int world)
{
printf("Hello World! \n");
}
};
int main(void)
{
Parent* myClass = new Child();
client_config* myClientConfig = (client_config *)malloc(sizeof(client_config));
myClientConfig->on_connect = myClass->myCallback;
return 0;
}
は、コンパイラはコンパイル時にこう言われる、
Error 1 error C3867: 'Parent::myCallback': function call missing argument list; use '&Parent::myCallback' to create a pointer to member
Error 2 error C2440: '=' : cannot convert from 'void (__thiscall Parent::*)(void *,int)' to 'void (__cdecl *)(void *,int)'
誰もが構造体の関数ポインタにクラスのメンバ関数をバインドする方法を指摘することができますか私はここで間違っていますか?