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. Tutorial Object Array

Tutorial Object Array

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresjsontutorialquestion
3 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.
  • R Offline
    R Offline
    Reagan Conservative
    wrote on last edited by
    #1

    Anyone point me to a good tutorial for Object Array List with Serialization? Many thanks

    AF Pilot

    S 1 Reply Last reply
    0
    • R Reagan Conservative

      Anyone point me to a good tutorial for Object Array List with Serialization? Many thanks

      AF Pilot

      S Offline
      S Offline
      sashoalm
      wrote on last edited by
      #2

      http://www.tenouk.com/visualcplusmfc/visualcplusmfc10b.html[^] One of the easiest ways to use a CObList object is to add new elements to the tail, or bottom, of the list and to remove elements from the head, or top, of the list. The first element added to the list will always be the first element removed from the head of the list. Suppose you're working with element objects of class CAction, which is your own custom class derived from CObject. A command-line program that puts five elements into a list and then retrieves them in the same sequence is shown here: #include #include class CAction : public CObject { private: int m_nTime; public: // Constructor stores integer time value CAction(int nTime) { m_nTime = nTime; } void PrintTime() { TRACE("time = %d\n", m_nTime); } }; int main() { CAction* pAction; // action list constructed on stack CObList actionList; int i; // inserts action objects in sequence {0, 1, 2, 3, 4} for (i = 0; i < 5; i++) { pAction = new CAction(i); // no cast necessary for pAction actionList.AddTail(pAction); } // retrieves and removes action objects // in sequence {0, 1, 2, 3, 4} while (!actionList.IsEmpty()) { // cast required for return value pAction = (CAction*) actionList.RemoveHead(); pAction->PrintTime(); delete pAction; } return 0; } Here's what's going on in the program. First a CObList object, actionList, is constructed. Then the CObList::AddTail member function inserts pointers to newly constructed CAction objects. No casting is necessary for pAction because AddTail() takes a CObject pointer parameter and pAction is a pointer to a derived class. Next the CAction object pointers are removed from the list of the objects deleted. A cast is necessary for the returned value of RemoveHead() because RemoveHead() returns a CObject pointer that is higher in the class hierarchy than CAction. When you remove an object pointer from a collection, the object is not automatically deleted. The delete statement is necessary for deleting the CAction objects.

      There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blai

      R 1 Reply Last reply
      0
      • S sashoalm

        http://www.tenouk.com/visualcplusmfc/visualcplusmfc10b.html[^] One of the easiest ways to use a CObList object is to add new elements to the tail, or bottom, of the list and to remove elements from the head, or top, of the list. The first element added to the list will always be the first element removed from the head of the list. Suppose you're working with element objects of class CAction, which is your own custom class derived from CObject. A command-line program that puts five elements into a list and then retrieves them in the same sequence is shown here: #include #include class CAction : public CObject { private: int m_nTime; public: // Constructor stores integer time value CAction(int nTime) { m_nTime = nTime; } void PrintTime() { TRACE("time = %d\n", m_nTime); } }; int main() { CAction* pAction; // action list constructed on stack CObList actionList; int i; // inserts action objects in sequence {0, 1, 2, 3, 4} for (i = 0; i < 5; i++) { pAction = new CAction(i); // no cast necessary for pAction actionList.AddTail(pAction); } // retrieves and removes action objects // in sequence {0, 1, 2, 3, 4} while (!actionList.IsEmpty()) { // cast required for return value pAction = (CAction*) actionList.RemoveHead(); pAction->PrintTime(); delete pAction; } return 0; } Here's what's going on in the program. First a CObList object, actionList, is constructed. Then the CObList::AddTail member function inserts pointers to newly constructed CAction objects. No casting is necessary for pAction because AddTail() takes a CObject pointer parameter and pAction is a pointer to a derived class. Next the CAction object pointers are removed from the list of the objects deleted. A cast is necessary for the returned value of RemoveHead() because RemoveHead() returns a CObject pointer that is higher in the class hierarchy than CAction. When you remove an object pointer from a collection, the object is not automatically deleted. The delete statement is necessary for deleting the CAction objects.

        There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blai

        R Offline
        R Offline
        Reagan Conservative
        wrote on last edited by
        #3

        Thanks very much for your assistance!

        AF Pilot

        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