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::vector<Zoo> allZoos;
Zoo ourCityZoo;
ourCityZoo.animals.push_back(new Cat());
//Uncommenting any of the lines below causes error:
//allZoos.push_back(ourCityZoo);
//allZoos.clear();
return 0;
}
Declaring allZoos
is okay, but calling any of its member functions causes the compiler error: (The full error log was so long, not posted)
C2259: 'Animal' : cannot instantiate abstract class c:\boost_1_49_0\boost\ptr_container\clone_allocator.hpp 34 1
This had nothing to do with boost's noncopyable utility class and custom new_clone
functions and I tried them with no luck. How can that be solved?
(I'm using VS2010)