关于智能指针的使用问题请教

wc3204 2018-11-27 10:38:55
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;
}
...全文
511 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
henysugar 2018-12-04
  • 打赏
  • 举报
回复
你这么提问,太不尊重大家了。就这么一贴代码。。。。 并且代码也有缺失,例如clientid_t 就没定义。
英雄@末路 2018-12-04
  • 打赏
  • 举报
回复
怎么编译不过,哪行报错,报的什么错?

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧