
21 Mar
2009
21 Mar
'09
10:25 p.m.
The following code does not compile in VS2008: #include <boost/ptr_container/ptr_map.hpp> class A { public: virtual void is() = 0; }; class B : public A { public: 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.