我想学习boost共享指针中的自定义解除分配器。
我包括:
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
创建了简单的界面:
class deleter
{
public:
void delete_ptr(void * ptr)
{
delete ptr;
};
};
class plugin: public deleter
{
public:
virtual boost::shared_ptr<std::string> pass_and_modify_data( boost::shared_ptr<std::string> a) =0;
};
一个简单的课程
#include "plug_in_interface.h"
class my_plugin: public plugin
{
public:
virtual boost::shared_ptr<std::string> pass_and_modify_data( boost::shared_ptr<std::string> a)
{
return boost::shared_ptr<std::string>(new std::string, boost::bind( &my_plugin::delete_ptr, _1 ) );
}
};
但它不希望在下一个编译器错误的情况下编译到库中:
Error 7 error C2440: 'newline' : cannot convert from 'std::string *' to 'deleter *' c:\program files (x86)\boost\include\boost-1_48\boost\bind\mem_fn.hpp 333 1 DemoPlugin
Error 8 error C2647: '->*' : cannot dereference a 'void (__thiscall deleter::* const )' on a 'std::string *' c:\program files (x86)\boost\include\boost-1_48\boost\bind\mem_fn.hpp 333 1 DemoPlugin
我该怎么办?如何修改我使用客户删除器boost::shared_ptr<std::string>(new std::string, boost::bind( &my_plugin::delete_ptr, _1 ) );
创建共享ptr的方式?我的绑定有什么问题?