Boost logo

Boost Users :

From: Darin Adler (darin_at_[hidden])
Date: 2002-08-27 12:56:44


On Tuesday, August 27, 2002, at 09:23 AM, Olaf Petzold wrote:

> 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.

     -- Darin


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