How can I do it?? PLEASE HELP ME??

This is a discussion on How can I do it?? PLEASE HELP ME?? within the C++ Programming forums, part of the General Programming Boards category; I need to know how I can declare a vector with an identifier I know that doesn't make much sense ...

  1. #1
    Shanedudddy2
    Guest

    Question How can I do it?? PLEASE HELP ME??

    I need to know how I can declare a vector with an identifier I know that doesn't make much sense so heres some pseudo code to explain

    vertex_type vert(identifier) //this declares that vert is of the vertex type.

    Please understand this and help??

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    ~

    Please elaborate. If you have a type vertex_type, declaring

    vertex_type vert

    would make vert of type vertex_type. From your pseudocode all I get is maybe you want a constructor or something...?

    I'm confused though.

  3. #3
    Shanedudddy2
    Guest

    Sorry about the confusion

    Sorry about the confusion, I read it later but didn't make sense

    I want to be able to declare a vector with a name that is different each time the user clicks the left mouse button.
    For example
    1 click= vertex_type v1
    2nd click= vertex_type v2
    How would I do this with out declaring 50 million vertex_types??

    Hope you understand this

  4. #4
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    ~

    Array.

    vertex_type* v;

    v = (vertex_type)malloc(num * sizeof(v));

    Then when the user clicks:

    ++num;
    v = (vertex_type)realloc(v, num * sizeof(v));

    Words of notice:
    That code is not tested. Also, malloc and realloc are nasty ugly dirty old C functions (well, they're not that bad, but most people would prefer new). But I don't know how to reallocate memory allocated with new without losing data other than creating a temporary array, filling it with the original array data, deleting the orig. array, recreating the orrig. array with the new size, filling up to orig. size the new array with the data from the temporary array. (-_- phew). There's probably a better way, but unfortunately I don't know it

  5. #5
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    You could use an STL container; like a vector.
    Code:
    #include <vector>
    // ...
    std::vector<vertex_type> vertexlist;
    
    OnClick(...)
    {
         vertexlist.push_back(vertex_type(...));
    }

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21