私はこのコードを持っています:
関数ポインタへの Typedef
typedef bool(*tMyFunc)(tSomeTypeDef);
関数ポインターは、Obj-C クラスのコールバック関数を指すメンバー var を宣言するために使用されます。
@interface MyClass : NSObject
{
tSomeTypeDef _someValue;
tMyFunc _callback;
}
- (void) registerNotificationWithCallback:(tMyFunc)callback;
@end
@implementation MyClass
- (void) registerNotificationWithCallback:(tMyFunc)callback {
_callback = callback;
}
- (void) didSomething:(NSNotification*)notification {
if (_callback)
_callback(_someValue);
}
@end
C++ クラスで、tMyFunc 関数ポインターの代わりにファンクターを渡したい
class MyOtherClass {
MyClass* m_instance;
public:
bool operator ()(tSomeTypeDef val);
}
MyOtherClass::MyOtherClass()
{
//... init m_instance, then register callback as follows
[m_instance registerNotificationWithCallback:*this];
}
bool MyOtherClass::operator ()(tSomeTypeDef val)
{
return false;
}
エラーでコンパイルします
'MyOtherClass' から 'tMyFunc' (別名 'bool(*)(tSomeTypeDef)') への実行可能な変換はありません