Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7620877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:03:21+00:00 2026-05-31T04:03:21+00:00

I need to have a std::vector of boost::ptr_vector s. To make their management easier,

  • 0

I need to have a std::vector of boost::ptr_vectors. 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)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:03:23+00:00Added an answer on May 31, 2026 at 4:03 am

    Actually, reading into where the error appears would’ve helped. It’s stated clear and plainly in the Boost source:

    template< class T >
    inline T* new_clone( const T& r )
    {
        //
        // @remark: if you get a compile-error here,
        //          it is most likely because you did not
        //          define new_clone( const T& ) in the namespace
        //          of T.
        //
        T* res = new T( r );
        BOOST_ASSERT( typeid(r) == typeid(*res) &&
                      "Default new_clone() sliced object!" );
        return res;
    }
    

    If you don’t specify a way to clone the type, it will try to do so by simply copying it, which isn’t possible with abstract classes. Add an appropriate clone method to the abstract_class and a new_clone function in its namespace and you’ll be fine.

    Here‘s a fixed version of your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say, I have a std::vector<SomeClass *> v; in my code and I need to
I have a table represented by a std::vector where every element is a boost::fusion::vector
I have the following: typedef std::function<void(const EventArgs&)> event_type; class Event : boost::noncopyable { private:
I have a std::vector with n elements. Now I need to pass a pointer
I have an std::vector -like class that is compiled with Visual C++ 2008. There's
Usually like this: #include <boost/assign/std/vector.hpp> vector<int> v; v += 1,2,3,4,5; Except for a: #include
i need to serialize directory tree. i have no trouble with this type: std::map<
I have a std::vector of values for which I know the maximum size, but
I have written some C++ code that generates a std::vector. I also have a
I am trying to sort a vector below using boost::phoenix library. The class Foo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.