Export (0) Print
Expand All

__raise

Emphasizes the call site of an event.

__raise method-declarator;

Remarks

From managed code, an event can only be raised from within the class where it is defined. See Event Handling in Managed Code for more information.

The keyword __raise causes an error to be emitted if you call a non-event.

// EventHandlingRef_raise.cpp
struct E {
   __event void func1();
   void func1(int) {
   }

   void func2() {
   }

   void b() {
      __raise func1();
      __raise func1(1);  // C3745: 'int Event::bar(int)': 
                         // only an event can be 'raised'
      __raise func2();   // C3745
   }
};

int main() {
   E e;
   __raise e.func1();
   __raise e.func1(1);  // C3745
   __raise e.func2();   // C3745
}

Managed events can also be called as a functor (implicit function call operator) of the event name.

// EventHandlingRef_raise2.cpp
// compile with: /clr
#using <mscorlib.dll>
__delegate void Del(int);

public __gc struct S
{
   __event Del * E;
   void Fire(int i)
   {
      E(i);
   }
};

int main()
{
   S * p = new S;
   p -> Fire(5);   // functor
}

See Also

C++ Keywords | Event Handling Keywords | Managed Extensions for C++ Reference | event_source | event_receiver | __event | __hook | __unhook

Show:
© 2014 Microsoft