Results 1 to 3 of 3

Thread: Dynamic array of pointers vs dynamic array of objects

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    28

    Dynamic array of pointers vs dynamic array of objects

    Hello Smart people!
    Can someone explain to me the difference between dynamic array of pointers vs dynamic array of objects by giving a real life example. Following is the code that I am using for dynamic array of objects. I am skipping initialization and other member functions.

    class Inventory {
    Item *itemList;
    int idx, count, size;
    public:
    void appendItem (char ttl[]);
    void resizeArray();
    };

    void Inventory::appendItem (char ttl[])
    { if (count == size)
    {resizeArray(); }
    itemList[count].set(ttl)

    }

    void Inventory::resizeArray()
    {Item *itm = new Item[size ++];
    if (itm == 0) {cout << "Out of memory\n"; exit(1); }
    for (int i = 0; i < count; i++)
    {itm[i] = itemList[i]; }
    delete [] itemList;
    itemList = itm;
    }

    how this code will change to allocate an array of item pointers of type Item*?????

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    Please use [code] tags and that's terrible style by the way.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    28
    Hi wey!
    I was not asking for critisize my style.
    I have asked for specific help.
    But I have figured this out already.
    So thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width