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

  1. #1

    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


    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

    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



    vertex_type* v;

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

    Then when the user clicks:

    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
    You could use an STL container; like a vector.
    #include <vector>
    // ...
    std::vector<vertex_type> vertexlist;

Popular pages Recent additions subscribe to a feed