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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to call a function from another class

How to call a function from another class

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
10 Posts 2 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.
  • G Offline
    G Offline
    gmlnd
    wrote on last edited by
    #1

    I have a CFormView Project. I'm trying to call a function which is located in LeftMenu.cpp which is my implementation file (CLeftMenu::CLeftMenu() : CFormView(CLeftMenu::IDD)), from AnonWasher.cpp which Defines the class behaviors for the application.(CAnonWasherApp) This is the function that I'm trying to call: void CLeftMenu::GetCheckedItems() { char *checkedItems=NULL; if( m_hWnd != NULL ) { CMainFrame *main = (CMainFrame*)m_hWnd; checkedItems=main->GetCheckedArray(); } } When I call GetCheckedItems from AnonWasher, I get undeclared Identifier error. I don't know how I could do this.

    D 1 Reply Last reply
    0
    • G gmlnd

      I have a CFormView Project. I'm trying to call a function which is located in LeftMenu.cpp which is my implementation file (CLeftMenu::CLeftMenu() : CFormView(CLeftMenu::IDD)), from AnonWasher.cpp which Defines the class behaviors for the application.(CAnonWasherApp) This is the function that I'm trying to call: void CLeftMenu::GetCheckedItems() { char *checkedItems=NULL; if( m_hWnd != NULL ) { CMainFrame *main = (CMainFrame*)m_hWnd; checkedItems=main->GetCheckedArray(); } } When I call GetCheckedItems from AnonWasher, I get undeclared Identifier error. I don't know how I could do this.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      You are failing to #include a .H file. Which line is the compiler complaining about?

      G 1 Reply Last reply
      0
      • D David Crow

        You are failing to #include a .H file. Which line is the compiler complaining about?

        G Offline
        G Offline
        gmlnd
        wrote on last edited by
        #3

        I have all the .h files. Could there be any other problems? Thanks.

        D 1 Reply Last reply
        0
        • G gmlnd

          I have all the .h files. Could there be any other problems? Thanks.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Having them and #including them are two different things.

          G 1 Reply Last reply
          0
          • D David Crow

            Having them and #including them are two different things.

            G Offline
            G Offline
            gmlnd
            wrote on last edited by
            #5

            Yes, I have all the #include .h files both my classes.

            D 1 Reply Last reply
            0
            • G gmlnd

              Yes, I have all the #include .h files both my classes.

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Ok, what about my other question regarding the compiler error?

              G 1 Reply Last reply
              0
              • D David Crow

                Ok, what about my other question regarding the compiler error?

                G Offline
                G Offline
                gmlnd
                wrote on last edited by
                #7

                It was complaining about GetCheckedItems();

                D 1 Reply Last reply
                0
                • G gmlnd

                  It was complaining about GetCheckedItems();

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  At the top of anonwasher.cpp, do you have #include "leftmenu.h"?

                  G 1 Reply Last reply
                  0
                  • D David Crow

                    At the top of anonwasher.cpp, do you have #include "leftmenu.h"?

                    G Offline
                    G Offline
                    gmlnd
                    wrote on last edited by
                    #9

                    Yes, I do have the #include "leftmenu.h" at top of anonwasher.cpp. Maybe I need a pointer to that class.

                    D 1 Reply Last reply
                    0
                    • G gmlnd

                      Yes, I do have the #include "leftmenu.h" at top of anonwasher.cpp. Maybe I need a pointer to that class.

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      Yes, your CAnonWasherApp class will need a CLeftMenu object in order to access the GetCheckedItems() method. Whether it is a pointer or not is up to you and the project's design.

                      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