Re: 7.1 vs 8.0: Inheritance and Events

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



rwf_20 wrote:
Consider the following (/clr:oldSyntax):

[code snipped]

In VisualStudio 2003, this code calls the base class event handler:
"myPanel::OnPanelActivated()"

This is clearly a bug.

In VisualStudio 2005, this code calls the derived class event handler:
"derivedPanel::OnPanelActivated()"

This is correct.

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.

I agree.

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.

I assume that what you want is the 2005 behavior in the 2003 build, right?
In that case, I would think that you'd have to do something like provide a
pure virtual function in your base class that every derived class must
override. Form the pointers to members from within the implementations of
that virtual function, and call that new virtual function from your
add_PanelActivated function rather than composing the pointer to member
directly at that point.

-cd


.



Relevant Pages

  • Re: c++ : a baseclass, derived classes, a list of baseclass pointers, a problem.
    ... > I overwrote the virtual function func1() in each derived class. ... > How can I execute the right function? ... > I use a pointer to the baseclass to loop trough ... You could cast to the base class and investigate the vtable pointer, ...
    (comp.programming)
  • Re: Classes from pointers?
    ... you have a pointer to a base class which really points to a derived class, ... polymorphism is to call a virtual function which does the right thing no ... Consider using a reference counted smart pointer instead ...
    (comp.lang.cpp)
  • sizeof(object) is different in ANSI and Unicode
    ... A class having no member variables and only a method sizeof ... I have the answer for this of how in works in ANSI. ... form a pointer to an empty object that is distinct from a pointer to ... For a class with virtual function, size of a virtual function is a ...
    (comp.lang.cpp)
  • Re: Why sizeof(struct) is different in C and C++ ?
    ... >> My conceptual view is a stack of base classes, ... For "ordinary" inheritance where each class inherits from exactly one immediate ... for just a single virtual function table pointer. ...
    (comp.lang.cpp)
  • Re: is it good, is it bad or plain eeevil ?
    ... > This is a virtual function call regardless of how call_vfun was called ... If sword is 'given' to player (that is pointer is passed), ... virtual method. ...
    (comp.lang.cpp)