c++ - Is it bad practice to implement a graph's nodes as a vector of pointers? -


i attempting implement graph in c++ each node instance of class a. first instinct represent collection of nodes in graph object vector of objects of type a.

however, wanted implement following functionality well: suppose overload + operator when g_2 = g_0 + g_1 (where g's instances of graph class), g_2's nodes consist of combined nodes of g_0 , g_1. if modify of nodes in g_2, g_0 , g_1's nodes remain unchanged , in sense g_2 no longer remain sum of g_0 , g_1. however, if instead represent nodes in graph vector of pointers objects of type a, modifying g_2 modify g_0 , g_1, , vice versa, desirable project working on.

that being said, can't suspect having vector of pointers data member dangerous, don't know enough say.

a vector of pointers fine. need take care of memory management of objects yourself, doable.

you need allocate objects new a() , delete them delete pointer_to_a if want rid of them.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -