編譯器錯誤 C3718
只能在接收類別的成員函式內容中呼叫 ' event '
事件只能從接收類別呼叫。
範例
下列範例會產生 C3718:
// C3718.cpp
#define _ATL_ATTRIBUTES 1
#include "atlbase.h"
#include "atlcom.h"
[module(name="test")];
[object, uuid("00000000-0000-0000-0000-000000000001")]
__interface I
{
HRESULT f();
};
[event_source(com), coclass, uuid("00000000-0000-0000-0000-000000000002")]
struct E
{
__event __interface I;
};
[event_receiver(com)]
struct R
{
void b()
{
printf_s("B::bar()\n");
}
void HookAndRun(E* pE)
{
__hook(&I::f, pE->GetUnknown(), &R::b);
__raise pE->f();
}
};
int main()
{
CComObject<E>* pE;
CComObject<E>::CreateInstance(&pE);
__hook(&I::f, pE->GetUnknown(), &R::b, &r); // C3718
__raise pE->f();
// try the following lines instead
// R r;
// r.HookAndRun(pE);
}