$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Martin Bosticky (mbosticky_at_[hidden])
Date: 2003-03-18 11:07:00
Hi
Me and my colleagues have come across an issue when using a shared_ptr.
void myFunction(shared_ptr<myClass> const & vp_Pointer)
{
vp_Pointer->call any non-const function
}
i.e. a const shared_ptr doesn't prevent anyone from changing the
contents to which the pointer points. This makes sense as it behaves
like a normal pointer.
However, how can I pass a shared pointer into a function such that the
data can not be modified? i.e. how can I pass an equivalent of "myClass
const *" ?
I tried static casting to shared_ptr<const myClass> which works but
causes a new constructor to be called which means I loose the efficiency
of passing by reference.
Any comments of suggestions would be greatly appreciated.
Martin Bosticky
Software Engineer
Action Information Management Ltd.
Tel: (01225) 711200
Fax: (01225) 711222
Email: mbosticky_at_[hidden]