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. global carray

global carray

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
7 Posts 4 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
    jafrazee
    wrote on last edited by
    #1

    how can i make a carray global. i have tried adding it in a header but it does not like my definion. i have tried making it extern but it again does not like my definion. it works great within the dialog it is created in. i am using it to hold report data. thank you. this is how i have it created. ******************************************* in h file ******************************************* typedef struct{ CString a; CString b; CString c; } MYCARRAYSTRUCT; ******************************************** in cpp file ******************************************** *************created global for the cpp MYCARRAYSTRUCT mycarraystruct; CArray mycarray; *************my funtion do{ ........ mycarraystruct.a = m_pSet->firstfield; mycarraystruct.b = m_pSet->secondfield; ..................... m_pSet->MoveNext(); }while.............

    M R D 3 Replies Last reply
    0
    • J jafrazee

      how can i make a carray global. i have tried adding it in a header but it does not like my definion. i have tried making it extern but it again does not like my definion. it works great within the dialog it is created in. i am using it to hold report data. thank you. this is how i have it created. ******************************************* in h file ******************************************* typedef struct{ CString a; CString b; CString c; } MYCARRAYSTRUCT; ******************************************** in cpp file ******************************************** *************created global for the cpp MYCARRAYSTRUCT mycarraystruct; CArray mycarray; *************my funtion do{ ........ mycarraystruct.a = m_pSet->firstfield; mycarraystruct.b = m_pSet->secondfield; ..................... m_pSet->MoveNext(); }while.............

      M Offline
      M Offline
      Martin Ziacek
      wrote on last edited by
      #2

      Put it as a public member variable of your application class. Martin

      J 1 Reply Last reply
      0
      • M Martin Ziacek

        Put it as a public member variable of your application class. Martin

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

        that is another part of my problem. the external function that i want to use it in is another class.

        M 1 Reply Last reply
        0
        • J jafrazee

          how can i make a carray global. i have tried adding it in a header but it does not like my definion. i have tried making it extern but it again does not like my definion. it works great within the dialog it is created in. i am using it to hold report data. thank you. this is how i have it created. ******************************************* in h file ******************************************* typedef struct{ CString a; CString b; CString c; } MYCARRAYSTRUCT; ******************************************** in cpp file ******************************************** *************created global for the cpp MYCARRAYSTRUCT mycarraystruct; CArray mycarray; *************my funtion do{ ........ mycarraystruct.a = m_pSet->firstfield; mycarraystruct.b = m_pSet->secondfield; ..................... m_pSet->MoveNext(); }while.............

          R Offline
          R Offline
          Renjith Ramachandran
          wrote on last edited by
          #4

          You must define the extern declaration on the top of the .cpp file... otherwise your cpp doesnot know about the the structure you defined globally do it now..! Trace The Bugs...

          J 1 Reply Last reply
          0
          • J jafrazee

            how can i make a carray global. i have tried adding it in a header but it does not like my definion. i have tried making it extern but it again does not like my definion. it works great within the dialog it is created in. i am using it to hold report data. thank you. this is how i have it created. ******************************************* in h file ******************************************* typedef struct{ CString a; CString b; CString c; } MYCARRAYSTRUCT; ******************************************** in cpp file ******************************************** *************created global for the cpp MYCARRAYSTRUCT mycarraystruct; CArray mycarray; *************my funtion do{ ........ mycarraystruct.a = m_pSet->firstfield; mycarraystruct.b = m_pSet->secondfield; ..................... m_pSet->MoveNext(); }while.............

            D Offline
            D Offline
            Doug Joseph
            wrote on last edited by
            #5

            If your application is called MyDialog Add the following structure right after the line: #include "resource.h" in the file MyDialog.h (Not MyDialogDlg.h): /////////////////////////// typedef struct { CString a; CString b; CString c; } MYCARRAYSTRUCT; ////////////////////////// Right after the declaration of MyDialogApp() a little further down in the .h file, Add the line: /////////////////////////// MYCARRAYSTRUCT mm_Global; /////////////////////////// Now in your dialog's (it is now global). Add the following line into any subroutine /////////////////////////////////////////////////////////////////////////// MYCARRAYSTRUCT *m_GData = &( ( MyDialogApp * ) AfxGetApp() ) -> mm_Global; /////////////////////////////////////////////////////////////////////////// The above line sets up a pointer to the global mm_Global. Now you can refer to the variables as pointer extensions ('->'). Best of all, VS's autocompletion will give you a list of variables in the structure, and if you put a comment ('//') after each declaration, it will show them in the autocompletion as well. Be careful if you have a timer event, that you are not clobbering work. I've chased this problem from time to time. :laugh: Woo Hoo! That's it I hope this helps Doug Doug Joseph (Engineering Guy)

            1 Reply Last reply
            0
            • R Renjith Ramachandran

              You must define the extern declaration on the top of the .cpp file... otherwise your cpp doesnot know about the the structure you defined globally do it now..! Trace The Bugs...

              J Offline
              J Offline
              jafrazee
              wrote on last edited by
              #6

              yes i did that, but i found my problem. very stupid in my new class i forgot to add #include

              1 Reply Last reply
              0
              • J jafrazee

                that is another part of my problem. the external function that i want to use it in is another class.

                M Offline
                M Offline
                Martin Ziacek
                wrote on last edited by
                #7

                Declare your struct just before your application class. Declare your array as: public: CArray m_mycarray; in your appilication class. Write function like: CYourApp *GetApp() { return (CYourApp *)AfxGetApp(); } Declare your function (where you want use m_mycarray) as YourFunction(CArray & m_mycarray) And then you can use it as: YourFunction(GetApp()->m_mycarray); Is it possible? Martin

                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