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. Carray doubt

Carray doubt

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
5 Posts 5 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.
  • D Offline
    D Offline
    doctorpi
    wrote on last edited by
    #1

    Sorry if this is a silly question, but I'm a little confused. I've got a class MyClass and I want to have a CArray of MyClass objects in the Doc class of my application. Ex: In CMyAppDoc CArray <> m_myArray; My question is. How I have to declare and have acces to the array to touch the values of it directly (by reference) in the view? CMyAppView ????? Best Regards Dr. Pi

    D C J D 4 Replies Last reply
    0
    • D doctorpi

      Sorry if this is a silly question, but I'm a little confused. I've got a class MyClass and I want to have a CArray of MyClass objects in the Doc class of my application. Ex: In CMyAppDoc CArray <> m_myArray; My question is. How I have to declare and have acces to the array to touch the values of it directly (by reference) in the view? CMyAppView ????? Best Regards Dr. Pi

      D Offline
      D Offline
      Dr Kuulun
      wrote on last edited by
      #2

      Hi, i had the same problem and it seems to be impossible. i created a lot of instances of my class with 'new' and than i stored the pointers in an CObList or CObArray. This array stores only the pointers, so clean the memory up ('delete pClass') when deleting the array. Dr-Kuulun

      1 Reply Last reply
      0
      • D doctorpi

        Sorry if this is a silly question, but I'm a little confused. I've got a class MyClass and I want to have a CArray of MyClass objects in the Doc class of my application. Ex: In CMyAppDoc CArray <> m_myArray; My question is. How I have to declare and have acces to the array to touch the values of it directly (by reference) in the view? CMyAppView ????? Best Regards Dr. Pi

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        Try this: CArray<CMyClass*,CMyClass*&> m_MyArray; And to acces any data: CMyClass* Temp = m_MyArray[i]; Temp->DoSomething(); Hope this helps ! Ced

        1 Reply Last reply
        0
        • D doctorpi

          Sorry if this is a silly question, but I'm a little confused. I've got a class MyClass and I want to have a CArray of MyClass objects in the Doc class of my application. Ex: In CMyAppDoc CArray <> m_myArray; My question is. How I have to declare and have acces to the array to touch the values of it directly (by reference) in the view? CMyAppView ????? Best Regards Dr. Pi

          J Offline
          J Offline
          jhwurmbach
          wrote on last edited by
          #4

          You are probably better off using the standardized std::vector class: std::vector< CMyClass > m_myArray; ... now you can fill the vector e.g. using push_back()... And now you can use CMyClass c = GetDocument()->m_myArray[0]; to access the first data item in the associated document. Hope this helps


          My opinions may have changed, but not the fact that I am right.

          1 Reply Last reply
          0
          • D doctorpi

            Sorry if this is a silly question, but I'm a little confused. I've got a class MyClass and I want to have a CArray of MyClass objects in the Doc class of my application. Ex: In CMyAppDoc CArray <> m_myArray; My question is. How I have to declare and have acces to the array to touch the values of it directly (by reference) in the view? CMyAppView ????? Best Regards Dr. Pi

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

            I have something similar in one of my projects. class CMyDoc : public CDocument { public: void GetAddressList( CDWordArray *pAddresses ); private: CDWordArray m_arrAddresses; }; void CMyDoc::GetAddressList( CDWordArray *pAddresses ) { pAddresses->RemoveAll(); pAddresses->Append(m_arrAddresses); } void CMyView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { CMyDoc *pDoc; CDWordArray arrAddresses; pDoc = GetDocument(); pDoc->GetAddressList(&arrAddresses); } Hope this helps, or at least gives you an idea.

            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