分享方式:


編譯器錯誤 C3712

'method': 事件處理常式方法必須傳回與來源 'method' 相同的類型

您已定義未傳回與來源事件方法相同類型的事件處理常式方法。 若要修正此錯誤,請為事件處理常式方法提供與來源事件方法相同的傳回類型。

下列範例會產生 C3712:

// C3712.cpp
// compile with: /c
[event_source(native)]
class CEventSrc {
public:
   __event void event1();
};

[event_receiver(native)]
class CEventRec {
public:
   int handler1() { return 0; }
   // try the following line instead
   // void handler1() {}

   void HookEvents(CEventSrc* pSrc) {
      __hook(&CEventSrc::event1, pSrc, &CEventRec::handler1);   // C3712
   }
   void UnhookEvents(CEventSrc* pSrc) {
      __unhook(&CEventSrc::event1, pSrc, &CEventRec::handler1);   // C3712
   }
};