c++11 - Creating a default deleter for shared_ptr for a specific type -
is there similar well, how custom deleter of std::unique_ptr work? shared_ptr
s?
when try creating default deleter smart pointers allegro_bitmap
pointers
namespace std { template<> class default_delete < allegro_bitmap > { public: void operator()(allegro_bitmap* ptr) { al_destroy_bitmap(ptr); } }; }
the compiler spits out
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\memory(696): warning c4150: deletion of pointer incomplete type 'allegro_bitmap'; no destructor called 1> c:\users\john\allegro\allegro-5.0.10-msvc-11.0\include\allegro5\bitmap.h(12) : see declaration of 'allegro_bitmap' 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\memory(482) : see reference function template instantiation 'void std::shared_ptr<allegro_bitmap>::_resetp<_ux>(_ux *)' being compiled 1> 1> [ 1> _ux=allegro_bitmap 1> ] 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\memory(482) : see reference function template instantiation 'void std::shared_ptr<allegro_bitmap>::_resetp<_ux>(_ux *)' being compiled 1> 1> [ 1> _ux=allegro_bitmap 1> ] 1> c:\users\john\documents\visual studio 2013\projects\blockstacking\blockstacking\systems.cpp(190) : see reference function template instantiation 'std::shared_ptr<allegro_bitmap>::shared_ptr<allegro_bitmap>(_ux *)' being compiled 1> 1> [ 1> _ux=allegro_bitmap 1> ] 1> c:\users\john\documents\visual studio 2013\projects\blockstacking\blockstacking\systems.cpp(190) : see reference function template instantiation 'std::shared_ptr<allegro_bitmap>::shared_ptr<allegro_bitmap>(_ux *)' being compiled 1> 1> [ 1> _ux=allegro_bitmap 1> ] 1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\memory(159): warning c4150: deletion of pointer incomplete type 'allegro_bitmap'; no destructor called 1> c:\users\john\allegro\allegro-5.0.10-msvc-11.0\include\allegro5\bitmap.h(12) : see declaration of 'allegro_bitmap' 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\memory(158) : while compiling class template member function 'void std::_ref_count<_ux>::_destroy(void)' 1> 1> [ 1> _ux=allegro_bitmap 1> ] 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\memory(694) : see reference class template instantiation 'std::_ref_count<_ux>' being compiled 1> 1> [ 1> _ux=allegro_bitmap 1> ] 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\memory(482) : see reference function template instantiation 'void std::shared_ptr<allegro_bitmap>::_resetp<_ux>(_ux *)' being compiled 1> 1> [ 1> _ux=allegro_bitmap 1> ] 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\memory(482) : see reference function template instantiation 'void std::shared_ptr<allegro_bitmap>::_resetp<_ux>(_ux *)' being compiled 1> 1> [ 1> _ux=allegro_bitmap 1> ]
on line
shared_ptr<allegro_bitmap> black(al_create_bitmap(groundwidth, tilesize));
i realize can pass deleter shared_ptr
, wondering if there way create default deleter don't have keep passing in same function every time create new bitmap.
thanks.
if can enforce convention allocate via std::make_unique
work:
std::shared_ptr<allegro_bitmap> bmp; ... bmp = std::make_unique<allegro_bitmap>();
the deleter move object, , therefore default_delete called upon object destruction. unfortunately, compiler can't enforce convention; not without custom types.
Comments
Post a Comment