CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #2
    Join Date
    Jan 2009
    Location
    Salt Lake City, Utah
    Posts
    82

    Re: Array of pointers

    First of all, it sounds like you want your 'array' to be of dynamic length. If this is the case, I highly recommend you use a vector instead of array. If using an array, you might do something like this:
    Code:
    // Creates the array
    // Have MAX_LIST_LENGTH defined beforehand, or just use literal here:
    TEnt list[MAX_LIST_LENGTH]; // ahoodin is right. put * symbol between 'TEnt' and 'list' on this line
    // loop through the array, creating and adding elements
    for(int i = 0; i < MAX_LIST_LENGTH; i++)
    {
        pos.Initialize(x,y,z);
        list[i] = new TEnt(pos);
    }
    However, if you decide to use a vector, it might look something like this:
    Code:
    #include <vector>
    ...
    std::vector<TEnt> list;
    for(int i = 0; i < NUMBER_OF_ITEMS; i++)
    {
        pos.Initialize(x,y,z);
        list.push_back(*(new TEnt(pos)));
    }
    Or, I could be totally off base here. Let me know if this helps.

    Edit: ahoodin (below) is right. I forgot we were working with pointers. Simply add the * symbol in that case.
    Last edited by Etherous; March 21st, 2009 at 01:12 PM.

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

Featured