ptr-vector

Can't make a vector of a class containing a ptr_vector<an_abstract_class>

十年热恋 提交于 2020-01-24 16:20:07
问题 I need to have a std::vector of boost::ptr_vector s. To make their management easier, I enclosed the boost::ptr_vector in a class ( Zoo ) and made a std::vector of it ( allZoos ). Look at a minimal code for reproducing this: #include <boost/ptr_container/ptr_vector.hpp> #include <boost/utility.hpp> class Animal { public: virtual char type() = 0; }; class Cat : public Animal { public: char type() { return 1; } }; class Zoo { public: boost::ptr_vector<Animal> animals; }; int main() { std:

boost::ptr_vector and find_if

强颜欢笑 提交于 2019-12-31 05:29:36
问题 I have a class: //header file class CMDatabase { class Try; typedef boost::shared_ptr<Try> TryPtr; typedef boost::ptr_vector<Try> TryVector; typedef TryVector::iterator TryVectorIterator; class Try { public: virtual ~Try(); virtual bool equal(CMDatabase::TryPtr mySd) = 0; }; }; //.cpp file class TryImpl : public CMDatabase::Try { bool equal(CMDatabase::TryPtr mySd) { //boost::shared_ptr<ServiceDataImpl> ServiceDataImplPtr; //const ServiceDataImplPtr pOtherData = dynamic_cast<const

boost::ptr_vector and find_if

我们两清 提交于 2019-12-02 11:37:17
I have a class: //header file class CMDatabase { class Try; typedef boost::shared_ptr<Try> TryPtr; typedef boost::ptr_vector<Try> TryVector; typedef TryVector::iterator TryVectorIterator; class Try { public: virtual ~Try(); virtual bool equal(CMDatabase::TryPtr mySd) = 0; }; }; //.cpp file class TryImpl : public CMDatabase::Try { bool equal(CMDatabase::TryPtr mySd) { //boost::shared_ptr<ServiceDataImpl> ServiceDataImplPtr; //const ServiceDataImplPtr pOtherData = dynamic_cast<const ServiceDataImplPtr>(mySd); //ServiceDataImpl *pOtherData = dynamic_cast<ServiceDataImpl *>(mySd.get()); return

How to erase elements from boost::ptr_vector

我怕爱的太早我们不能终老 提交于 2019-12-01 04:06:47
So I'm trying to get rid of my std::vector's by using boost::ptr_vector. Now I'm trying to remove an element from one, and have the removed element deleted as well. The most obvious thing to me was to do: class A { int m; }; boost::ptr_vector<A> vec; A* a = new A; vec.push_back(a); vec.erase(a); But this won't even compile (see below for the full error message). I've tried the erase/remove idiom like I would on a std::vector but all the algorithms of boost::ptr_vector turn out to be slightly different from those in std::vector. So my questions: How do I remove a pointer from a ptr_vector? Do I

How to erase elements from boost::ptr_vector

与世无争的帅哥 提交于 2019-12-01 01:12:34
问题 So I'm trying to get rid of my std::vector's by using boost::ptr_vector. Now I'm trying to remove an element from one, and have the removed element deleted as well. The most obvious thing to me was to do: class A { int m; }; boost::ptr_vector<A> vec; A* a = new A; vec.push_back(a); vec.erase(a); But this won't even compile (see below for the full error message). I've tried the erase/remove idiom like I would on a std::vector but all the algorithms of boost::ptr_vector turn out to be slightly