Reputation: 2424
I found somewhere this piece of code:
boost::shared_ptr<const Foo> pFoo = boost::make_shared<const Foo>();
What's the aim of the const
keyword here?
Upvotes: 3
Views: 2523
Reputation: 6427
shared_ptr<const Foo> ptr
is similar to const Foo * ptr
. So it's a pointer to const Foo
.
Upvotes: 3
Reputation: 143
std::shared_ptr<const T>
allows you just to read from pointed address in memory.
Upvotes: 2
Reputation: 11787
Its very simple, it really is just a pointer pointing to a const
Foo. The code, currently, which is:
boost::shared_ptr<const Foo> pFoo = boost::make_shared<const Foo>();
Is the basic equivalent of
const Foo * pFoo
The meaning of const
here is regular as with const
pointers
The advantage of this is that the pointer is read-only, because of const
ness
Upvotes: 5
Reputation: 66451
It creates a shared const Foo
- that is, const
has its regular meaning.
Upvotes: 2