c++ - Good practice for referencing objects -


i'm working on project several different object semantically linked , i'm looking way let objects refer each other. put pointers in each object , link them together. in special case there no heap objects (at least not create while writing code, vector internally might on page). came idea have class stores list of unique ids , share id objects need them known.

is practice? there other, better ways this?

background: project settled in academic background. not know students or other people contribute this. skill level not known, not high. not using pointers can @ least ensure objects not deleted accidentally or out of stupidity.

edit:

what led me idea of unique id our usage of vectors store data. 1 thing stl containers lot copying containees. why i'm not sure pointers work well. same simple indices of vector elements, content and/or it's order might change.

is pratice?

in experience, no. sort of unique id crap 1 more thing has managed, , managed correctly or you'll kinds of weird bullshit spraying over. worked on product once used idea , portion of our bugs, , more maintenance problems, caused having remember stupid id tracking variable. granted, implementation quite convoluted (borderline insane) , it's easy better being done, it's still 1 more thing deal when have unique id generated system: address of variable.

there other, better ways this?

yeah, use pointers.

unfortunately there's no such thing smart pointer (that know of anyway) can used refer objects owned elsewhere now, have make sure enforce issue through policy , documentation. it's weakness, yes, still better alternative tracking , id, can have same problems , more.

if you're interested in smart pointers can used such purposes might interested in latest blog entry.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -