Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > user defined Shared ptr ( restict to certain data type )

Reply
Thread Tools

user defined Shared ptr ( restict to certain data type )

 
 
Pallav singh
Guest
Posts: n/a
 
      10-22-2010
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
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      10-22-2010
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
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      10-22-2010
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
 
Reply With Quote
 
Vladimir Jovic
Guest
Posts: n/a
 
      10-22-2010
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.
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      10-22-2010
Pallav singh <> 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.)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible to restict connection speed? HotRod Wireless Networking 6 12-19-2005 01:43 PM
is (!ptr) or (ptr) valid way to check for NULL or NOT NULL? G Fernandes C Programming 9 02-27-2005 03:07 AM
const ptr to const ptr ? franco ziade C Programming 3 02-17-2005 04:30 AM
How to convert a double **ptr in a double const ** const ptr? Heiko Vogel C Programming 3 09-14-2004 10:23 AM
what's the difference between delete ptr and ptr=0 -dont they accomplish the same Sid C++ 5 07-29-2004 03:42 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57