编译器错误 C3703
“event handler”:事件处理程序方法必须具有和源“事件”相同的存储类
事件具有与其挂钩的事件处理程序不同的存储类。 例如,如果事件处理程序是静态成员函数,并且该事件不是静态的,则会发生此错误。 若要修复此错误,请为事件和事件处理程序提供相同的存储类。
以下示例生成 C3703:
// C3703.cpp
// C3703 expected
#include <stdio.h>
[event_source(type=native)]
class CEventSrc {
public:
__event static void MyEvent();
};
[event_receiver(type=native)]
class CEventHandler {
public:
// delete the following line to resolve
void MyHandler() {}
// try the following line instead
// static void MyHandler() {}
void HookIt(CEventSrc* pSource) {
__hook(CEventSrc::MyEvent, pSource, &CEventHandler::MyHandler);
}
void UnhookIt(CEventSrc* pSource) {
__unhook(CEventSrc::MyEvent, pSource, &CEventHandler::MyHandler);
}
};
int main() {
CEventSrc src;
CEventHandler hnd;
hnd.HookIt(&src);
__raise src.MyEvent();
hnd.UnhookIt(&src);
}