I have a class with function called void deallocatorFunc(ClassA *p) I want using templates make it possible to write boost::shared_ptr< ClassA > ptr(new ClassA()); instead of boost::shared_ptr< ClassA > ptr(new ClassA(), deallocatorFunc);. I want it to spread on to my class and its inheritors. How to do such thing in C++? (I really need my peculiar destructor for that special class, while I want to keep super simple API).
I have a class with function called void deallocatorFunc(ClassA *p) I want using templates
Share
You can use specialization for your class and wrap the standard implementation. Here’s a self-contained compilable example.
Output:
Note
As given, the specialization doesn’t work for derived classes of A!
For that to work, you need more trickery:
Template specialization based on inherit class