#include #include using std::shared_ptr; template< typename T > struct arrdel { void operator ()(T const *p) { delete[] p; } }; int main() { shared_ptr sp(new int(1)); // pointer to int[] array - custom deleter shared_ptr p1(new int[10], arrdel()); // ... or lambda shared_ptr p2(new int[10'000'000], [](int *p) { delete[] p; }); // ... or the one from the library shared_ptr p3(new int[3]{1, 2, 3}, std::default_delete()); std::cout << p3.get()[2] << " " << *p3 << std::endl; // since c++17 this will work shared_ptr p4(new int[3]{4, 5, 6}); std::cout << p4[2] << std::endl; }