HI
i want to implement shared ptr for my project.
Q How can we restrict my shared_ptr to certain class object ? only
allowed class object should be only using it.
for others shared_ptr should fail.
Q Can we support inheritance here ?
Thanks
Pallav Singh
|
|
0
|
|
|
|
Reply
|
singh.pallav (123)
|
10/22/2010 6:52:12 AM |
|
On 10/22/10 07:52 PM, Pallav singh wrote:
> HI
>
> i want to implement shared ptr for my project.
Why don't you just use tr1::shared_ptr?
> Q How can we restrict my shared_ptr to certain class object ? only
> allowed class object should be only using it.
> for others shared_ptr should fail.
Why?
> Q Can we support inheritance here ?
In what sense?
--
Ian Collins
|
|
0
|
|
|
|
Reply
|
Ian
|
10/22/2010 7:31:49 AM
|
|
On Oct 22, 8:31 am, Ian Collins <ian-n...@hotmail.com> wrote:
> On 10/22/10 07:52 PM, Pallav singh wrote:
> > i want to implement shared ptr for my project.
> Why don't you just use tr1::shared_ptr?
> > Q How can we restrict my shared_ptr to certain class object ? only
> > allowed class object should be only using it.
> > for others shared_ptr should fail.
> Why?
One obvious reason might be to use an invasive implementation.
This eliminates one major source of problems with
{boost,tr1,std}::shared_ptr.
--
James Kanze
|
|
0
|
|
|
|
Reply
|
James
|
10/22/2010 7:55:42 AM
|
|
Pallav singh wrote:
> HI
>
> i want to implement shared ptr for my project.
>
> Q How can we restrict my shared_ptr to certain class object ? only
> allowed class object should be only using it.
> for others shared_ptr should fail.
You can have a typedef in the classes that you want to allow, which will
be somehow used in your custom shared_ptr. The compilation will fail for
other types.
|
|
0
|
|
|
|
Reply
|
Vladimir
|
10/22/2010 8:06:24 AM
|
|
Pallav singh <singh.pallav@gmail.com> wrote:
> Q How can we restrict my shared_ptr to certain class object ? only
> allowed class object should be only using it.
> for others shared_ptr should fail.
Can you modify the classes in question? If yes, you could inherit them
from a class (which might be empty if you don't need anything from it)
and make your shared_ptr accept only classes of that type.
(Of course that doesn't stop someone from inheriting from that base
class, but if the purpose is to catch errors rather than restrict what
people can do, which is usually the case, then it will work perfectly
for that.)
|
|
0
|
|
|
|
Reply
|
Juha
|
10/22/2010 8:12:20 AM
|
|