std::unique_ptr destroys the object when it goes out of scope.
// #include <tango.h> #include <string> #include "nxIO.h" std::unique_ptr<NXSelWriter> wrptr; int tng_nexus_init() { ... std::unique_ptr<NXSelWriter> wrp(new NXSelWriter ( selectorName)); wrptr = std::move(wrp); ... } int tng_nexus_record() { wrptr->loopStep(); } int tng_nexus_final() { wrptr->closeEntry(); wrptr->closeFile(); // // no need to delete wrptr here, done by std::unique_ptr // } int main(int argc, char ** argv) { tng_nexus_init(); for(int i =0 ;i<10; i++){ tng_nexus_record(); } tng_nexus_final(); }