user defined Shared ptr ( restict to certain data type )

P

Pallav singh

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
 
I

Ian Collins

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?
 
V

Vladimir Jovic

Pallav said:
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.
 
J

Juha Nieminen

Pallav singh said:
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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top