#include#include class Base { public: virtual ~Base() {} }; class Derived : public Base { public: ~Derived() { std::cout << "Deleting Derived" << std::endl; } }; int main() { boost::TypePtr ptr(new Derived()); ptr.reset(); return 0; }
#includeIn this example, we define a template function `func` that takes a pointer to an object of any type `T`. The function creates a smart pointer of type `boost::TypePtr#include template void func(T* t) { boost::TypePtr ptr(t); std::cout << "Pointer created" << std::endl; } int main() { func(new Derived()); return 0; }