Boost logo

Boost Users :

From: Olaf Petzold (yg-boost-users_at_[hidden])
Date: 2002-08-28 02:12:58


> > int main()
> > {
> > boost::shared_ptr<Doc> lp_doc( new Doc );
> >
> > std::copy(lp_doc->foo().begin(), lp_doc->foo().end(),
> > std::ostream_iterator<double>(cout, " ") );
> > cout << endl;
> > }
> >
> > `std::vector<double, std::allocator<double> >& Doc::foo()' is protected
>
> This is not a shared_ptr problem. The same thing would happen if you
> were using Doc *. You could fix it by using Doc const *, and in the
> shared_ptr case you can fix it by using boost::shared_ptr<Doc const>.
>
> Or you could fix the problem by using different names for the const and
> non-const foo() functions. Your original design shows some confusion
> about C++ rules about access control. Making something protected does
> not affect whether it's considered when doing overload resolution, so
> it's impractical to have a pair of const/not-const functions overloaded
> the way you do.

Using protected did show that the non const member was taken - a "furtune"
for me of testing the public interface. Only the derived classes should use
protected ( I did hide that part from snippet). I hoped, that std::copy
takes the const iterators, after looking into the headers - it takes
generell iterators.

Thanks
Olaf


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