Alternatives to pointer-to-pointers in C++? -
i find myself @ few places in game wanting use pointer-to-pointer in design. example, have class openglrenderer
creates meshes given vertex/indice/texcoord data, materials given material props, etc. , class resourcemanifest
caches meshes/materials file , upon loading 1 of these resources creates instance of using openglrenderer
. there coupling there.
i typically employ raii design when coding tempts me following relationship:
resourcemanifest(openglrenderer** renderer);
because when opengl context has been torn down , opengl state-specific stuff needs reinitialized, such when recreating window, recreate openglrenderer
, let constructor/destructor work , resourcemanifest
using never wiser.
what wondering if enough justification of using plain old pointer-to-pointers, there more modern tools or techniques available? i've been looking @ various smart_ptrs example, not deal problem @ hand, want recreate managed object without passing out new smart_ptrs.
as others have stated, reference smart pointer.
however, if want provide functionality beyond smart pointerness make code iterator if underlying data structures not homogeneous. again, matter of how you'll use pointer pointer. whatever interface use wrapped in smart pointer.
Comments
Post a Comment