[GiNaC-list] memory allocation, matrices
    David Fang 
    fang at csl.cornell.edu
       
    Mon Sep 11 23:32:14 CEST 2006
    
    
  
Hi,
>  > In C++, you should never invoke dtors explicitly, unless you do
>  > such dirty tricks as discussed in June on this list:
>  > <http://www.ginac.de/pipermail/ginac-list/2006-June/thread.html>.
Another place where one might explicitly call dtors is when writing
placement new/delete operators in C++.  But let's not get too carried away
on that subject...
> Thanks! This thread is exactly what I was looking for. Can you briefly
> explain the meaning of reinterpret_cast<GiNaC::ex*>? Wouldn't
> <GiNaC::ex*> be sufficient? Also, in GiNaC, if I have an expression
> that is actually a symbol, say, how do I determine at compile time
> what destructor to call, ~ex or ~symbol?
libstdc++ often uses a helper function to deduce the argument type, and
hence its destructor (copied straight from gcc's <bits/stl_construct.h>):
namespace std {
  template <class _Tp>
    inline void
    _Destroy(_Tp* __pointer)
    { __pointer->~_Tp(); }
}
Then "std::_Destroy(&your_object);" will call the appropriate in-charge
destructor, be it virtual or non-virtual.
For maximum portability, I wouldn't count on std::_Destroy existing, you
you might as well define your own, until such a function is standardized.
> I will need to invoke the destructor explicitly in the deallocation
> code of my Objective C object.
However, I don't know the syntax in Objective C.
Fang
    
    
More information about the GiNaC-list
mailing list