当我知道我插入的指针时,如何从boost::ptr_set中删除?
How do I delete from a boost::ptr_set when I know the pointer I inserted?
当我知道我插入的指针时,我如何从boost::ptr_set
中删除?(我有一个this指针指向插入的类对象)。
下面是一个人为的例子来展示我正在尝试做的事情:
boost::ptr_set<ServerConnection1> m_srv_conns1;
ServerConnection1 *this_ptr;
m_srv_conns1.insert(this_ptr = new ServerConnection1);
m_srv_conns1.erase(this_ptr); //It won't work!
有一个指向插入对象的this
指针,我如何告诉boost::ptr_set
到erase(this)
?注意:我不再在插入的对象中,但我有一个指向它的指针。
其中一个评论是我没有满足boost::ptr_set
的所有要求。有什么要求?
我认为提供一个< operator
会做的伎俩?
- 将
m_srv_conns1.erase(this_ptr);
更改为m_srv_conns1.erase(*this_ptr);
- 将以下代码放入
ServerConnection1
类中:
m_srv_conns1.erase(this_ptr);
更改为m_srv_conns1.erase(*this_ptr);
ServerConnection1
类中: bool operator<(const ServerConnection1 & sc1) const
{
return (this < &sc1); //Pointer comparison
}
试试m_srv_conns1.erase(*this_ptr);
.
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- boost::进程间消息队列引发错误
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- cmake如何在fedora工作站中找到boost静态库包
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- Boost Graph Library,修复节点大小
- 什么是"#include <boost/functional/hash.hpp> "?
- 基于boost的程序的静态链接——zlib问题
- C++:如何在CLion IDE中安装Boost
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 如何在boost beast http请求中设置http头
- Boost Spirit,获取迭代器内部语义动作
- boost::shared_ptr和std::shared-ptr的同居
- 我如何在void*和boost共享ptr之间切换
- 数据突然从 Boost shared_array/ptr 中删除
- 我可以用std::shared_ptr而不是boost::shared-ptr构建boost库吗
- 使用boost lambda构造创建初始化的智能ptr的容器
- Boost Scoped Ptr-声明与分配
- 如何转发声明boost智能ptr
- boost ptr容器与普通容器的区别