|
Boost Users : |
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2008-06-13 01:49:04
Christopher Harvey skrev:
> 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 <boost/ptr_container/ptr_map.hpp>
>
> class Filter
> {
> public:
> virtual void blah() const = 0;
> };
>
> class SpecificFilter : public Filter
> {
> public:
>
> SpecificFilter() : Filter() {}
> void blah() const
> {
> }
> };
>
> int main()
> {
> boost::ptr_map<unsigned char, Filter> map;
> map[0].blah();
> }
> /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.
No matter what, then you can't create an object of abstract type.
operator[]() needs to create a default argument.
> 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?
with operator[](), a default constructed element is inserted. With
at(key), an exception is thrown.
As for double insertions, then the same happens as in a normal map.
-Thorsten
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net