Runtime overriding of virtual functions

From: Dim St Thomas (
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
  virtual void draw();

class B
  A *getWidget() { return m_a; }
  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++?


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? ...
  • 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" _ ...
  • 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 { ...
  • 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) ...
  • 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 ...