R
rwf_20
Consider the following (/clrldSyntax):
// myPanel.h
public __gc class myPanel {
public:
__delegate void PanelActivationHandler();
__event PanelActivationHandler* PanelActivated;
virtual void OnPanelActivated() {
std::cerr << "myPanel::OnPanelActivated()\n";
}
};
public __gc class derivedPanel : public myPanel {
public:
virtual void OnPanelActivated() {
std::cerr << "derivedPanel::OnPanelActivated()\n";
}
void generateEvent() {
PanelActivated();
}
};
// end myPanel.h
// test.cpp
int main() {
derivedPanel* p = new derivedPanel();
p->add_PanelActivated(new myPanel:anelActivationHandler(p,
&myPanel::OnPanelActivated));
p->generateEvent();
return 0;
}
// end test.cpp
In VisualStudio 2003, this code calls the base class event handler:
"myPanel::OnPanelActivated()"
In VisualStudio 2005, this code calls the derived class event handler:
"derivedPanel::OnPanelActivated()"
So, my questions are:
Which one should be called? I would think that the 2005 behavior is
correct; however, the static scoping of the function pointer
(&myPanel::OnPanelActivated) concerns me.
Is there a way to make this work in both versions? Keep in mind that,
in my real application, the code calling add_PanelActivated knows only
the base type.
Thanks in advance,
Ryan
// myPanel.h
public __gc class myPanel {
public:
__delegate void PanelActivationHandler();
__event PanelActivationHandler* PanelActivated;
virtual void OnPanelActivated() {
std::cerr << "myPanel::OnPanelActivated()\n";
}
};
public __gc class derivedPanel : public myPanel {
public:
virtual void OnPanelActivated() {
std::cerr << "derivedPanel::OnPanelActivated()\n";
}
void generateEvent() {
PanelActivated();
}
};
// end myPanel.h
// test.cpp
int main() {
derivedPanel* p = new derivedPanel();
p->add_PanelActivated(new myPanel:anelActivationHandler(p,
&myPanel::OnPanelActivated));
p->generateEvent();
return 0;
}
// end test.cpp
In VisualStudio 2003, this code calls the base class event handler:
"myPanel::OnPanelActivated()"
In VisualStudio 2005, this code calls the derived class event handler:
"derivedPanel::OnPanelActivated()"
So, my questions are:
Which one should be called? I would think that the 2005 behavior is
correct; however, the static scoping of the function pointer
(&myPanel::OnPanelActivated) concerns me.
Is there a way to make this work in both versions? Keep in mind that,
in my real application, the code calling add_PanelActivated knows only
the base type.
Thanks in advance,
Ryan