jeudi 17 février 2011

c++ deletion of an incomplete type

Today I had an issue when I implemented a smart_ptr for my dblite project.
I wanted to move out the dependency for some reason (iphone,ipad).

In this library I am using the pimpl idiom and once I replaced the shared_ptr of boost by my version of it, I faced a warning of the compiler: 

warning: possible problem detected in invocation of delete operator:

Hopefully I found the solution to my problem here:
Private implementation using smart pointers and deletion trouble

I didn't understand clearly what was the workaround used by boost::shared_ptr to work on incomplete type, but it was surely useful. As far as I understood, the trick would be to instantiate an deleter object when the pointer is assigned so at this moment the type is complete.

ps: I found the trick!
using a function pointer to delete.
It is very well explained here: