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