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. Problem in Accessing CArray object

Problem in Accessing CArray object

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelpquestion
10 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.
  • A Offline
    A Offline
    Atul23
    wrote on last edited by
    #1

    Hi All, I am using CArray object to store the strings in array. I used this object in one class where i add strings in to CArray object. I want to access this object in other class. But when i access it in other class it gives me garbage values. So how can i access it in another class. I created CArray object on the stack. Is there any need to create it on Heap. Thanks in Advance Atul

    C 1 Reply Last reply
    0
    • A Atul23

      Hi All, I am using CArray object to store the strings in array. I used this object in one class where i add strings in to CArray object. I want to access this object in other class. But when i access it in other class it gives me garbage values. So how can i access it in another class. I created CArray object on the stack. Is there any need to create it on Heap. Thanks in Advance Atul

      C Offline
      C Offline
      chandu004
      wrote on last edited by
      #2

      how are you passing your object from one class to the other?

      A 1 Reply Last reply
      0
      • C chandu004

        how are you passing your object from one class to the other?

        A Offline
        A Offline
        Atul23
        wrote on last edited by
        #3

        I am accesssing CArray object in other class as follows CWebsiteCreatorWizard *pPtr = (CWebsiteCreatorWizard *)GetParent(); if(NULL != pPtr) nTotalWebPageCount = pPtr->m_WebSitePagesAry.GetSize(); Where CWebsiteCreatorWizard is wizardseet class in which i declare CArray m_WebSitePagesAry is array of strings could u guess why I get here Garbage value in nTotalWebPageCount. Regards A23

        C D 2 Replies Last reply
        0
        • A Atul23

          I am accesssing CArray object in other class as follows CWebsiteCreatorWizard *pPtr = (CWebsiteCreatorWizard *)GetParent(); if(NULL != pPtr) nTotalWebPageCount = pPtr->m_WebSitePagesAry.GetSize(); Where CWebsiteCreatorWizard is wizardseet class in which i declare CArray m_WebSitePagesAry is array of strings could u guess why I get here Garbage value in nTotalWebPageCount. Regards A23

          C Offline
          C Offline
          chandu004
          wrote on last edited by
          #4

          Atul23 wrote:

          CWebsiteCreatorWizard *pPtr = (CWebsiteCreatorWizard *)GetParent();

          first make sure that, the above line fetches you the correct pointer of your required class. to do that, first, you define a simple integer variable, say int temp=47; in CWebsiteCreatorWizard class. then try to access it and see its value. if its value is 47, then, we can proceed to find the next step to localise the problem.

          A 1 Reply Last reply
          0
          • C chandu004

            Atul23 wrote:

            CWebsiteCreatorWizard *pPtr = (CWebsiteCreatorWizard *)GetParent();

            first make sure that, the above line fetches you the correct pointer of your required class. to do that, first, you define a simple integer variable, say int temp=47; in CWebsiteCreatorWizard class. then try to access it and see its value. if its value is 47, then, we can proceed to find the next step to localise the problem.

            A Offline
            A Offline
            Atul23
            wrote on last edited by
            #5

            Hi Chandu, I can not access value of temp in other class by using pointer. so could u give me next steps please. Thanks in Advance A23

            C T 2 Replies Last reply
            0
            • A Atul23

              Hi Chandu, I can not access value of temp in other class by using pointer. so could u give me next steps please. Thanks in Advance A23

              C Offline
              C Offline
              chandu004
              wrote on last edited by
              #6

              so it means that, you are not able to properly pass your object handle to the place where required. now, define it globally and try to access.

              1 Reply Last reply
              0
              • A Atul23

                Hi Chandu, I can not access value of temp in other class by using pointer. so could u give me next steps please. Thanks in Advance A23

                T Offline
                T Offline
                ThatsAlok
                wrote on last edited by
                #7

                in continuation with Chandu(good reply) better look for singleton design!

                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                Never mind - my own stupidity is the source of every "problem" - Mixture

                cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

                C 1 Reply Last reply
                0
                • T ThatsAlok

                  in continuation with Chandu(good reply) better look for singleton design!

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                  Never mind - my own stupidity is the source of every "problem" - Mixture

                  cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

                  C Offline
                  C Offline
                  chandu004
                  wrote on last edited by
                  #8

                  ThatsAlok wrote:

                  better look for singleton design!

                  can you explain? thank you. ------------------------------------------

                  Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.

                  T 1 Reply Last reply
                  0
                  • C chandu004

                    ThatsAlok wrote:

                    better look for singleton design!

                    can you explain? thank you. ------------------------------------------

                    Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.

                    T Offline
                    T Offline
                    ThatsAlok
                    wrote on last edited by
                    #9

                    chandu004 wrote:

                    can you explain?

                    please refer this :- Singleton Pattern[^] instead of making global variable.. it is better to use singleton class.!

                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                    Never mind - my own stupidity is the source of every "problem" - Mixture

                    cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

                    1 Reply Last reply
                    0
                    • A Atul23

                      I am accesssing CArray object in other class as follows CWebsiteCreatorWizard *pPtr = (CWebsiteCreatorWizard *)GetParent(); if(NULL != pPtr) nTotalWebPageCount = pPtr->m_WebSitePagesAry.GetSize(); Where CWebsiteCreatorWizard is wizardseet class in which i declare CArray m_WebSitePagesAry is array of strings could u guess why I get here Garbage value in nTotalWebPageCount. Regards A23

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

                      Is GetParent() returning a valid (i.e., the actual parent) pointer? Note that just because the value is non-NULL does not mean it is valid. Is m_WebSitePagesAry non-empty? Even if it wasn't, nTotalWebPageCount would be 0 (assuming that the answer to my first question is "yes").


                      "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      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