user defined Shared ptr ( restict to certain data type )

Discussion in 'C++' started by Pallav singh, Oct 22, 2010.

  1. Pallav singh

    Pallav singh Guest

    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
    Pallav singh, Oct 22, 2010
    #1
    1. Advertising

  2. Pallav singh

    Ian Collins Guest

    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
    Ian Collins, Oct 22, 2010
    #2
    1. Advertising

  3. Pallav singh

    James Kanze Guest

    On Oct 22, 8:31 am, Ian Collins <> 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
    James Kanze, Oct 22, 2010
    #3
  4. 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.
    Vladimir Jovic, Oct 22, 2010
    #4
  5. 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.)
    Juha Nieminen, Oct 22, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sid
    Replies:
    5
    Views:
    1,072
  2. Heiko Vogel
    Replies:
    3
    Views:
    556
    Method Man
    Sep 14, 2004
  3. franco ziade

    const ptr to const ptr ?

    franco ziade, Feb 17, 2005, in forum: C Programming
    Replies:
    3
    Views:
    394
    franco ziade
    Feb 17, 2005
  4. G Fernandes
    Replies:
    9
    Views:
    590
    DHOLLINGSWORTH2
    Feb 27, 2005
  5. Jason

    difference between *ptr++ and ++*ptr ?

    Jason, May 15, 2005, in forum: C Programming
    Replies:
    19
    Views:
    6,532
    Chris Torek
    May 19, 2005
Loading...

Share This Page