I canโt understand for life what happened to this code:
ClassA & doSomething (std::set<boost::shared_ptr<ClassB const> const > const & someSet) { std::set<boost::shared_ptr<ClassB> > secondSet; for (std::set<boost::shared_ptr<ClassB const> const >::const_iterator it = someSet.begin(); it != someSet.end(); it++) { if (checkSomething(*it)) secondSet.insert(boost::const_pointer_cast<ClassB>(*it)); } }
When I try to compile, I get the following errors in line 4 (beginning of the for loop) from g ++:
/usr/include/c++/4.4/ext/new_allocator.h:79: error: 'const _Tp* __gnu_cxx::new_allocator<_Tp>::address(const _Tp&) const [with _Tp = const boost::shared_ptr<const ClassB>]' cannot be overloaded /usr/include/c++/4.4/ext/new_allocator.h:76: error: with '_Tp* __gnu_cxx::new_allocator<_Tp>::address(_Tp&) const [with _Tp = const boost::shared_ptr<const ClassB>]'
If I modify the std::set declaration to contain a non-constant boost::shared_ptr , the code compiles fine, but that means that I can not ensure const-correctness matches in my code.
Does anyone have any ideas as to what might cause these errors? I searched both Google and StackOverflow with no luck.
The following is a minimal (non) working example:
#include <set> #include <boost/shared_ptr.hpp> class ClassB; class ClassA { public: ClassA & doSomething (std::set<boost::shared_ptr<ClassB const> const > const & someSet); }; ClassA & doSomething (std::set<boost::shared_ptr<ClassB const> const > const & someSet) { std::set<boost::shared_ptr<ClassB> > secondSet; for (std::set<boost::shared_ptr<ClassB const> const >::const_iterator it = someSet.begin(); it != someSet.end(); it++) { if (checkSomething(*it)) secondSet.insert(boost::const_pointer_cast<ClassB>(*it)); } return (*this); }
source share