Export (0) Print
Expand All
Expand Minimize

Compiler Error C3730

'event': an event must have both an add and a remove method

When creating user-defined add and remove methods for an event, both add and remove need to be present.

C3730 is only reachable using /clr:oldSyntax.

The following sample generates C3730:

// C3730.cpp
// compile with: /clr:oldSyntax
#using <mscorlib.dll>
using namespace System;

public __delegate void MyDel();

__gc class EventSource
{
public:
   MyDel *pE;

   __event void add_E(MyDel* p)   // C3730, uncomment remove_E to resolve
   {
      pE = static_cast<MyDel*> (Delegate::Combine(pE, p));
   }
/*
   __event void remove_E(MyDel* p)
   {
      pE = static_cast<MyDel*> (Delegate::Remove(pE, p));
   }
*/
   __event void raise_E()
   {
      if (pE != 0)  pE->Invoke();
   }
};

int main()
{
}

Community Additions

ADD
Show:
© 2014 Microsoft