Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Don't I understand virtual functions?

Don't I understand virtual functions?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelplounge
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Joep
    wrote on last edited by
    #1

    Hi, I can't figure out the cause of the following: I've derived a general dialog class (say CMyDialogBase) from CDialog and in that class I've put OnOK() with ClassWizard. Then I've derived another dialog classes (say CMyDialogFinal from CMyDialogBase and put in OnOK() as well. Now when I call OnOK() from within CMyDialogFinal::OnOK() I expect CMyDialogBase::OnOK() to be called, but instead CDialog:OnOK() is called, even when I write the call like this CMyDialogBase::OnOK(). With OnCancel I don't get this problem - skipping the base class. Can anyone tell me what is going on here? Thx, Joep

    L E 2 Replies Last reply
    0
    • J Joep

      Hi, I can't figure out the cause of the following: I've derived a general dialog class (say CMyDialogBase) from CDialog and in that class I've put OnOK() with ClassWizard. Then I've derived another dialog classes (say CMyDialogFinal from CMyDialogBase and put in OnOK() as well. Now when I call OnOK() from within CMyDialogFinal::OnOK() I expect CMyDialogBase::OnOK() to be called, but instead CDialog:OnOK() is called, even when I write the call like this CMyDialogBase::OnOK(). With OnCancel I don't get this problem - skipping the base class. Can anyone tell me what is going on here? Thx, Joep

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You have inherit two classes from CDialog: CDialog virtual OnOK() | v CMyDialogBase virtual OnOK() | v CMyDialogFinal virtual OnOK() and implemented in all classes OnOK(). If you will call always CMyDialogBase::OnOK from class MyDialogFinal, then delete function MyDialogFinal::OnOK(). The system will always find the virtual-function in CMyDialogbase and execute this function. If you use virtual-function, the system checks all class (start at class from where you call the function) until it finds the function in this class or a higher-class. I hope that help's.

      1 Reply Last reply
      0
      • J Joep

        Hi, I can't figure out the cause of the following: I've derived a general dialog class (say CMyDialogBase) from CDialog and in that class I've put OnOK() with ClassWizard. Then I've derived another dialog classes (say CMyDialogFinal from CMyDialogBase and put in OnOK() as well. Now when I call OnOK() from within CMyDialogFinal::OnOK() I expect CMyDialogBase::OnOK() to be called, but instead CDialog:OnOK() is called, even when I write the call like this CMyDialogBase::OnOK(). With OnCancel I don't get this problem - skipping the base class. Can anyone tell me what is going on here? Thx, Joep

        E Offline
        E Offline
        Erik Funkenbusch
        wrote on last edited by
        #3

        Are you certain that you have capitalized OnOK the same in all classes? The fact that CDialog::OnOK is being called when you call CMyDialogBase::OnOK would seem to be a direct indicator that CMyDialogBase::OnOK doesn't exist (or may be spelled or capitalized differently).

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups