c++ - Retrieving pointers from a vector -



c++ - Retrieving pointers from a vector -

i've been working on project uses graph-based api. have need of beingness able traverse graph , force pointers existing nodes list (in case, std::vector).

of course, 1 time i'm done traversing graph, want take pointers , assign them fellow member variables of class. problem, of course, trying re-create pointers vector class variables. issue results having store nodes in vector cast pointers base of operations class, cast them actual type when passed class fellow member variables.

roughly speaking, want is:

std::vector<smart_pointer<node_base> > nodes; nodes.push_back( node ); //"node" smart pointer of derived type node_base ( ... ) { myclass::member_node_ref = static_cast<node_type>( ( *vector_node_iterator )); //member_node_ref smart pointer of derived node type //vector_node_iterator iterator of vector<node_base> object }

all works fine until re-create constructor terminates. when happens, pointer references destroyed.

this consistent understand vectors of pointers, i'm not surprised @ behavior, though had hoped vector of smart_pointer objects work around it. in end, can't quite figure out how avoid pointer static_cast, know undoing here. is, have multiple derived types i'm passing around, can't away static_cast. have couple vague thoughts ( perchance involving boost), thought i'd go looking other opinions in case there's i'm missing...

c++ pointers vector static-cast

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -