G
Guest
All -
I am facing couple of problems with events in CLI C++.
If i have an interface that declares few events, and a ref class implements
that interface, should it do anything extra from events perspective?
interface class IMyClass
{
public:
event MyDeleg^ MyEvent;
}
ref class MyClass : IMyClass
{
public:
event MyDeleg^ MyEvent;
}
Compiler says MyClass must provide an implementation of MyEvent::add, which
i presume is explicit event specification, which i dont want to do. (C3766)
Remember that with VS 2003, interface in events tended to be a bit dodgy -
generating warning "C4803". But it used to work.
Is there something extra i am missing out?
And another intersting bit is that, if i dont implement IMyClass in MyClass,
and while i try and raise the event <see code below>
ref class MyClass // No implementation of IMyClass
{
event MyDeleg^ MyEvent;
void Fire_MyEvent()
{
if(MyEvent != nullptr) // *** Error C3918 ***
MyEvent();
}
}
So if we dont do this check for nullness, will the compiler do this bit
automatically for us? If so, that z cool. In VS 2003, guess we used to check
the __event ptr for nullness.
Thanks in advance.
Regardz
Grafix
I am facing couple of problems with events in CLI C++.
If i have an interface that declares few events, and a ref class implements
that interface, should it do anything extra from events perspective?
interface class IMyClass
{
public:
event MyDeleg^ MyEvent;
}
ref class MyClass : IMyClass
{
public:
event MyDeleg^ MyEvent;
}
Compiler says MyClass must provide an implementation of MyEvent::add, which
i presume is explicit event specification, which i dont want to do. (C3766)
Remember that with VS 2003, interface in events tended to be a bit dodgy -
generating warning "C4803". But it used to work.
Is there something extra i am missing out?
And another intersting bit is that, if i dont implement IMyClass in MyClass,
and while i try and raise the event <see code below>
ref class MyClass // No implementation of IMyClass
{
event MyDeleg^ MyEvent;
void Fire_MyEvent()
{
if(MyEvent != nullptr) // *** Error C3918 ***
MyEvent();
}
}
So if we dont do this check for nullness, will the compiler do this bit
automatically for us? If so, that z cool. In VS 2003, guess we used to check
the __event ptr for nullness.
Thanks in advance.
Regardz
Grafix