Thread: Algorithm help and multiple container ownership question...

  1. #1
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391

    Algorithm help and multiple container ownership question...

    Hi all,

    1) What is the general advice anyone can give about objects belonging to multiple containers (example: objects exits within a vector and a map )?

    2) If I need to create a map (a graph that is also a circuit) with a particular algorithm for creating the graph/circuit, if i need to circularly iterate the list or vector (not sure what i need right now) in order to create the graph, it seems that somehow defeats the purpose of the graph (since i'll have random or linear access to the elements)

    I realize these questions are vague at this point, but please ask me questions and try to anser these questions for me and maybe we can get the dialog ball rolling and we can work things out...

    srry for the vague, weird post, but really that's where I'm at right now...

    Thanks in advance,

    dudeomanodude
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    For your first question, containers do not contain the same object because objects are copied into the container (eg vector_of_objects.push_back(object)) . Two containers of pointers can contain pointers that point at the same object, but you can recognise such things because it is necessary to dereference the pointers to do anything with the objects the point to. As a rough rule of thumb (and there are always small exceptions to rules of thumb) if you have make declarations of any container<Type *> (where "container" = std::vector, std::list, ....) or you have to do any pointer operations on elements of a container, then you have a container of pointers. Common and recognisable pointer operations are computing the address of an object using the & operator, dereferencing the * operator, or using the "this" pointer within a member function when working with the container (eg a_container.push_back(this)).

    For your second question: you need to ask a clearer question.

Popular pages Recent additions subscribe to a feed