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. How to access function in different classes

How to access function in different classes

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
6 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
    jadhav123
    wrote on last edited by
    #1

    Hello all I am developing dialog based application. I have written a function in main dialog class and I want to access that in other classes. How to access this function in difffernt dialogs "onInitDialog()" function regards, Aj

    S H 2 Replies Last reply
    0
    • J jadhav123

      Hello all I am developing dialog based application. I have written a function in main dialog class and I want to access that in other classes. How to access this function in difffernt dialogs "onInitDialog()" function regards, Aj

      S Offline
      S Offline
      see me
      wrote on last edited by
      #2

      Hey....Simply create an object to that main dialog and call the function. If you want to call the function of main dialog from its child dialog then the child oen have a member m_pParentWnd to the MainDialog Then simply call m_pParentWnd->GetFunction(); :)

      Dream bigger... Do bigger...Expect smaller aji

      J 1 Reply Last reply
      0
      • S see me

        Hey....Simply create an object to that main dialog and call the function. If you want to call the function of main dialog from its child dialog then the child oen have a member m_pParentWnd to the MainDialog Then simply call m_pParentWnd->GetFunction(); :)

        Dream bigger... Do bigger...Expect smaller aji

        J Offline
        J Offline
        jadhav123
        wrote on last edited by
        #3

        Thanks for reply. can you please explain in detail that will help me. I am developing dialog based application. I have written a function in main dialog class(TestDlg.cpp) on button click i am opening new dialog (Say child.cpp ) I want to access the fuction from main dialog (TestDlg.cpp) from child.cpp. How to access the function from

        1 Reply Last reply
        0
        • J jadhav123

          Hello all I am developing dialog based application. I have written a function in main dialog class and I want to access that in other classes. How to access this function in difffernt dialogs "onInitDialog()" function regards, Aj

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          if main dialog is CMain and other class is CLocal you can use in local class CMain* m_Main=(CMain*)GetParent(); m_Main->your_variable or your_function(and also include "Main.h" in other classess)

          _**


          **_

          WhiteSky


          J 1 Reply Last reply
          0
          • H Hamid Taebi

            if main dialog is CMain and other class is CLocal you can use in local class CMain* m_Main=(CMain*)GetParent(); m_Main->your_variable or your_function(and also include "Main.h" in other classess)

            _**


            **_

            WhiteSky


            J Offline
            J Offline
            jadhav123
            wrote on last edited by
            #5

            I tried this CMain* m_Main=(CMain*)GetParent(); m_Main->Test(1); Test is function decleareed in CMainDlg; also CMainDlg.h included in child dialog class. it gives following errors; 'm_Main': identifier not found, even with argument-dependent lookup 'CMainDlg' : undeclared identifier 'm_Main' : undeclared identifier left of '->Test' must point to class/struct/union ‘CMainDlg’: identifier not found, even with argument-dependent lookup

            H 1 Reply Last reply
            0
            • J jadhav123

              I tried this CMain* m_Main=(CMain*)GetParent(); m_Main->Test(1); Test is function decleareed in CMainDlg; also CMainDlg.h included in child dialog class. it gives following errors; 'm_Main': identifier not found, even with argument-dependent lookup 'CMainDlg' : undeclared identifier 'm_Main' : undeclared identifier left of '->Test' must point to class/struct/union ‘CMainDlg’: identifier not found, even with argument-dependent lookup

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              You shall use CMainDlg instead CMain and where you declare CMainDlg

              _**


              **_

              WhiteSky


              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