Topic: Sun C++ templete destructor problem


Author: jamshid@ses.com (Jamshid Afshar)
Date: Mon, 22 Nov 1993 08:06:07 GMT
Raw View
[Redirected to comp.std.c++.]

While we're on the subject of explicit destructor calls, please make
sure that your compiler allows:

 void destroy(int* ip1, int* ip2, int& ir1, int& ir2) {
    ip1->int::~int();
    ip2->~int();
    ir1.int::~int();
    ir2.~int();
 }

It's very frustrating that I've only found one compiler which allows
all the above statements, even though they're completely legal
according to the ARM (at least recent printings).  Btw, the compiler
is by Edison Design Group, who unfortunately do not distribute their
product as an end-user compiler.

Also make sure your compiler handles the following template version.
Although it's not explicitly legal according to the ARM/WP, I hope and
bet it will be legal Standard C++.

 template<class T> inline void destroy(T& t) { t.~T(); }
 template<class T> inline void destroyp(T* t) { t->~T(); }

 class Foo { public: ~Foo(); };

 main() {
     Foo* f = new Foo;
     destroyp(f);
     destroy(*f);
     int* i = new int;
     destroyp(i);
     destroy(i);
 }

Btw, I hope explicit destructor calls will be allowed on any class
object, even if it doesn't have an explicit destructor.

Jamshid Afshar
jamshid@ses.com