This is a pretty simple question, so I'll just go ahead and paste the
test case i wrote. The compile errors are right below it.
(boost version: 1.34.1-r2)
#include <utility>
#include
class Filter
{
public:
virtual void blah() const = 0;
};
class SpecificFilter : public Filter
{
public:
SpecificFilter() : Filter() {}
void blah() const
{
}
};
int main()
{
boost::ptr_map map;
map[0].blah();
}
/usr/include/boost/ptr_container/ptr_map_adapter.hpp: In member function
'typename
boost::ptr_container_detail::associative_ptr_container, CloneAllocator>::reference
boost::ptr_container_detail::ptr_map_adapter_base::insert_lookup(const typename
boost::ptr_container_detail::associative_ptr_container, CloneAllocator>::key_type&) [with T = Filter, VoidPtrMap =
std::map > >, CloneAllocator
= boost::heap_clone_allocator]':
/usr/include/boost/ptr_container/ptr_map_adapter.hpp:268: instantiated
from 'typename
boost::ptr_container_detail::associative_ptr_container, CloneAllocator>::reference
boost::ptr_container_detail::ptr_map_adapter_base::operator[](const typename
boost::ptr_container_detail::associative_ptr_container, CloneAllocator>::key_type&) [with T = Filter, VoidPtrMap =
std::map > >, CloneAllocator
= boost::heap_clone_allocator]'
main.cc:24: instantiated from here
/usr/include/boost/ptr_container/ptr_map_adapter.hpp:168: error: cannot
allocate an object of abstract type 'Filter'
main.cc:5: note: because the following virtual functions are pure
within 'Filter':
main.cc:7: note: virtual void Filter::blah() const
I'm surprised it's not happy about the fact that blah is pure virtual
because this is a pointer container so I thought that wouldn't be a
problem.
Side note:
What happens when I try to access an element that doesn't exist, and
what happens when I insert two elements with the same key?
Thanks for reading,
Chris.