Showing posts with label smart pointer. Show all posts
Showing posts with label smart pointer. Show all posts

Monday, November 4, 2013

How to pass ownership of C objects to STL containers


Mixing C code with C++ code

I have a number of C entities (say Nodes), which I want to store to a std::vector temporarily.
The C interface I have to manipulate these nodes consists of:
  • Node *newNode();             constructs such nodes
  • void  freeNode(Node *);      frees such nodes
Can I use the RAII technique, so that they are properly freed when the vector goes out of scope?