关于智能指针的使用问题请教
class ZookeeperManager ;
typedef std::function<bool(ZookeeperManager &zookeeper_manager, int type, int state, const char *path)> WatcherFunType;
typedef std::function<void(ZookeeperManager &zookeeper_manager, int rc)> VoidCompletionFunType;
class ZookeeperManager
{
public:
ZookeeperManager();
/**
*
* @param const std::string & hosts 格式:ip:port,ip:port
* @param const std::string & root_path 根节点必须为有效路径,为了支持路径填写相对或者绝对路径
* @retval int32_t
* @author moon
*/
int32_t Init(const std::string &hosts, const std::string &root_path = "/", const clientid_t *client_id = NULL);
virtual ~ZookeeperManager();
/** 连接,阻塞操作,直到连接成功或者超时,超时后,也许会连接成功,更加稳妥的做法是,重新连接
*
* @param const std::string & hosts
* @param std::shared_ptr<WatcherFunType> global_watcher_fun
* @param int32_t recv_timeout_ms
* @param uint32_t conn_timeout_ms 连接超时时间,为0表示永久等待
* @retval int32_t
* @author moon
*/
int32_t Connect(std::shared_ptr<WatcherFunType> global_watcher_fun, int32_t recv_timeout_ms, uint32_t conn_timeout_ms = 30000);
/** 获得ClientID
*
* @retval const zookeeper::clientid_t *
* @author moon
*/
const clientid_t *GetClientID()
{
return &m_zk_client_id;
}
};
采用如下使用方式,不能编译通过,不知道错在什么地方,如何定义使用才能通过
using namespace zookeeper;
bool WatcherFun(ZookeeperManager &zookeeper_manager, int type, int state, const char *path)
{
bool bRet = false;
return bRet;
}
int main()
{
ZookeeperManager zkMana;
zkMana.Init("127.0.0.1:2181");
auto pFun= std::bind(WatcherFun, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,std::placeholders::_4);
// std::shared_ptr<WatcherFunType> pFun =make_shared(new WatcherFun);
/*std::shared_ptr<WatcherFunType>*/ // pFun = std::bind(WatcherFun, zkMana, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
zkMana.Connect(pFun,10);
return 0;
}