Boost logo

Boost :

Subject: [boost] [ptr_container] ptr_map + abstract class = error
From: Ross Levine (ross.levine_at_[hidden])
Date: 2009-03-21 18:25:11

The following code does not compile in VS2008:

#include <boost/ptr_container/ptr_map.hpp>

class A
        virtual void is() = 0;

class B : public A
        virtual void is() {}

int main()
        boost::ptr_map<int, A> c;
        int i = 1;
        c.insert(i, new B);
        A& my_ref = c[1]; // error: cannot instantiate abstract class

It seems that using operator[] creates a new A for an unmatched key,
which creates an abstract instance. Using the find method works fine.
Should this be documented? The example in the documentation uses
operator[] on an ABC, and thus shouldn't compile either.

Boost list run by bdawes at, gregod at, cpdaniel at, john at