This documentation is archived and is not being maintained.

Compiler Warning (level 1) C4803

'method' : the raise method has a different storage class from that of the event, 'event'

Event methods must have the same storage class as the event declaration. The compiler adjusts the event's methods so that the storage classes are the same.

This warning can occur if you have a class that implements an event from an interface. The compiler does not implicitly generate a raise method for an event in an interface. When you implement that interface in a class, the compiler does implicitly generate a raise method and that method will not be virtual, hence the warning.

See warning pragma for information on how to turn a warning off.

For more information, see Event Handling in Managed Code.

The following sample generates C4803:

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

public __delegate void Del();

__gc struct E
{
   Del* _pd1;
   virtual __event void add_E1(Del* pd1)
   {
      _pd1 = dynamic_cast<Del*> (Delegate::Combine(_pd1, pd1));
   }

   virtual __event void remove_E1(Del* pd1)
   {
      _pd1 = dynamic_cast<Del*> (Delegate::Remove(_pd1, pd1));
   }

   __event void raise_E1 ()   // C4803, add virtual
   {
      if (_pd1)
      {
         _pd1->Invoke();
      }
   }

   void func()
   {
      Console::WriteLine("In E::func()");
   }

};

int main()
{
   E* ep = new E;
   ep->E1 += new Del(ep, &E::func);
   ep->E1();
   ep->E1 -= new Del(ep, &E::func);
   ep->E1();
}
Show: