pointer to object destructor

D

dan

Hi All,
I've a question regarding function pointer and destructor.
Is it possible to create a typedef param (*myDestructorPointer)(), so
that I can assign
object->~myClassType() to my function pointer variable?

Definitely I have a proxy class, which can wrap several data types
from other libraries, but this data type can have destructor as
protected so I can't
compile if I use delete keyword to destroy wrapped object. I don't
know if other strategies exist

thank you, cheers,
w
 
P

Permostat

Hi All,
I've a question regarding function pointer and destructor.
Is it possible to create a typedef param (*myDestructorPointer)(), so
that I can assign
object->~myClassType() to my function pointer variable?

Definitely I have a proxy class, which can wrap several data types
from other libraries, but this data type can have destructor as
protected so I can't
compile if I use delete keyword to destroy wrapped object. I don't
know if  other strategies exist

thank you, cheers,
w

Blast it with piss.

sperm-
 
M

Michael Doubez

I've a question regarding function pointer and destructor.
Is it possible to create a typedef param (*myDestructorPointer)(), so
that I can assign
object->~myClassType() to my function pointer variable?

Definitely I have a proxy class, which can wrap several data types
from other libraries, but this data type can have destructor as
protected so I can't
compile if I use delete keyword to destroy wrapped object. I don't
know if  other strategies exist
 
P

Pavel

dan said:
Hi All,
I've a question regarding function pointer and destructor.
Is it possible to create a typedef param (*myDestructorPointer)(), so
that I can assign
object->~myClassType() to my function pointer variable?

Definitely I have a proxy class, which can wrap several data types
from other libraries, but this data type can have destructor as
protected so I can't
compile if I use delete keyword to destroy wrapped object. I don't
know if other strategies exist

thank you, cheers,
w
My understanding is that "The address of a destructor shall not be
taken" phrase (12.4-2) is a hint that pointer-to-member is also illegal
although I may be wrong. But, if I understand your problem correctly,
it's not necessary: you can expose the destructor via a regular static
function of a utility derived class:

class B { protected: ~B(); } // your data type with protected destructor
class BDestroyer : protected B { public: static DestroyB(B *b) {
assert(b); b->~B(); }

Now use BDestroyer::DestroyB(B *) in whatever manner you wanted to use
the destructor pointer.

Depending on your situation, you might also want to:
- templatize the solution with <B> as a template parameter
- prohibit creation of the utility class's instances

Hope this helps,
-Pavel
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top