如何施放boost :: shared_array< char> to boost :: shared_array< const char>?
解决方法
由于shared_array没有add_ref方法,您可以按如下方式模拟它:
struct MagicDeleter { MagicDeleter( boost::shared_array<char> ptr ) : ptr(ptr) {}; template<typename T> void operator()(T*) {} protected: boost::shared_array<char> ptr; }; ... boost::shared_array<char> orig_ptr( some_val ); boost::shared_array<const char> new_ptr( orig_ptr.get(),MagicDeleter(orig_ptr) );