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. Object Array / collections

Object Array / collections

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsdata-structuresquestion
4 Posts 3 Posters 3 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.
  • U Offline
    U Offline
    User 2382
    wrote on last edited by
    #1

    Im working on a little program that does on command drawing eventually plotting / cutting (Very lucky to have opportunity to experiment on high tech peice of machinary :o) )I had a program thatused a CArray collection but I need to have another two variables in a adition to a point. I tried using a class which had all neccissary variables and then tried to use it in a simar type collection but this didnt work. How should I go about this??? CObArray?? I need to be able to 'add'Items and then read items sequentially. thanks for the time

    B S 2 Replies Last reply
    0
    • U User 2382

      Im working on a little program that does on command drawing eventually plotting / cutting (Very lucky to have opportunity to experiment on high tech peice of machinary :o) )I had a program thatused a CArray collection but I need to have another two variables in a adition to a point. I tried using a class which had all neccissary variables and then tried to use it in a simar type collection but this didnt work. How should I go about this??? CObArray?? I need to be able to 'add'Items and then read items sequentially. thanks for the time

      B Offline
      B Offline
      Blake Miller
      wrote on last edited by
      #2

      You can create separate instances of the class using new. Then add the pointer to that class data to the CObArray. Just remember to create a function to properly delete items prior to emptying the array, or else you will discover that you have memory leaks. I usually use a for loop to fetch each item's pointer, delete the items via the pointer, then erase all the pointers by calling RemoveAll on the array when I am done with the data.

      1 Reply Last reply
      0
      • U User 2382

        Im working on a little program that does on command drawing eventually plotting / cutting (Very lucky to have opportunity to experiment on high tech peice of machinary :o) )I had a program thatused a CArray collection but I need to have another two variables in a adition to a point. I tried using a class which had all neccissary variables and then tried to use it in a simar type collection but this didnt work. How should I go about this??? CObArray?? I need to be able to 'add'Items and then read items sequentially. thanks for the time

        S Offline
        S Offline
        Sam Hobbs
        wrote on last edited by
        #3

        See: http://home.socal.rr.com/samhobbs/VC/Collections.html The CObList sample can probably be used as an exmple of a CObArray also, with the obvious variations. I think, however, that a CArray would be good too and might be easier. If you used it as in: CArray m_FieldsRecords; then it would store and retrieve your class items and you could delete everything with a simple: m_FieldsRecords.RemoveAll(); when you are through. So what was the problem with CArray? I have used them and they work well and are easy to use. I think it would be worthwhile to determine what the problem is and solve it.

        U 1 Reply Last reply
        0
        • S Sam Hobbs

          See: http://home.socal.rr.com/samhobbs/VC/Collections.html The CObList sample can probably be used as an exmple of a CObArray also, with the obvious variations. I think, however, that a CArray would be good too and might be easier. If you used it as in: CArray m_FieldsRecords; then it would store and retrieve your class items and you could delete everything with a simple: m_FieldsRecords.RemoveAll(); when you are through. So what was the problem with CArray? I have used them and they work well and are easy to use. I think it would be worthwhile to determine what the problem is and solve it.

          U Offline
          U Offline
          User 2382
          wrote on last edited by
          #4

          Well In fact I did solve the problem with the CArray and again Im sorry for the poorly written post I was a little mindboggled last night!!! I have a class whose constructor is as follows JPoint(CPoint CP, int state, int Ptool); This is the object I needed an array of.. In a SetCoordinates function I had code similar to this: FixedMap.Add(JPoint((100,100),0,1)); Still a newbee I assumed that (100,100) would be assumed to be the CPoint required by the JPoint constructor; And the fact I recieved no compiler errors lead me to beleive it should work. But when it came draw the points in another function nothing was displayed... The problem was not prefixing (100,100) with CPoint as follows FixedMap.Add(JPoint(CPoint(100,100),0,1)); Shouldve known better right???

          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