Runtime overriding of virtual functions

From: Dim St Thomas (dimstthomas_at_yahoo.com)
Date: 06/07/04


Date: 6 Jun 2004 19:44:18 -0700

Say you have a library with a header file that defines two classes:

class A
{
protected:
  virtual void draw();
};

class B
{
public:
  A *getWidget() { return m_a; }
private:
  A *m_a;
};

Is there any way of creating an instance of class B such that when it
calls the virtual draw function of m_a it will call a user derived
version of draw? The two ways I can think of are making the m_a
variable public and setting it equal to a class derived from A or
somehow modifying the virtual function table of the pointer returned
by getWidget(). I assume these are both hacks that are dependent on
the behaviour of the compiler. Has anyone got this to work using
Visual C++?

Thanks



Relevant Pages

  • Re: Runtime overriding of virtual functions
    ... > calls the virtual draw function of m_a it will call a user derived ... How do you intend to initialize this pointer anyway? ...
    (comp.lang.cpp)
  • Re: Drawing continuously(dynamically) in MFC .
    ... The key here is that you never actually draw anything on the window from anywhere except ... virtual void PlotPURE; ... class CDrawingBitmap: public CDrawingObject { ...
    (microsoft.public.vc.mfc)
  • Re: Graphic Draw Question
    ... One thing I forgot to mention in my previous response is if you decide to use the Polygon and SetWindowOrgEx method to draw your arrows then it might be best to make the first data item in the array of poly points the coordinates of the point of the arrow and set the "point" coordinates in the data to the values ... Private Declare Function SetWindowOrgEx Lib "gdi32" _ ...
    (microsoft.public.vb.general.discussion)
  • Re: transparent printing problem
    ... gifs into pictureboxes) and I want to print them on the page at certain ... are supposed to be able to draw transparent images. ... Private iBKMode As Long ... (ByVal hDC As Integer, ByVal nBkMode As Integer) ...
    (microsoft.public.vb.general.discussion)
  • Re: redraw pictureboxes in image????
    ... you can draw anything you want on your Form or into a picture box and you will have full control over how it looks and how it behaves. ... Private Enum Placement ... If .sPosition = pLeft Then ...
    (microsoft.public.vb.general.discussion)