Re: How to get rid of the new-initializer in a new-expression
"Alberto Ganesh Barbati" <AlbertoBarbati@libero.it> schrieb im Newsbeitrag
news:g2Ztj.248009$%k.378883@twister2.libero.it...
Why don't you simply define your new as:
#define NEW(T) TrackNew(new T)
and let the compiler deduce the type of the argument?
My example was a little simplified. In my original code, TrackNew() looks
more like this:
template <class T>
struct TrackNewImpl
{
static T* TrackNew( MemoryTracker& inst,
T* ptr, const char* file, int line )
{
// Do memory tracking for objects.
return ptr;
}
};
template <class T, std::size_t N>
struct TrackNewImpl<T[N]>
{
static T* TrackNew( MemoryTracker& inst,
T* ptr, const char* file, int line )
{
// Do memory tracking for arrays.
return ptr;
}
};
template <class T> typename extract<T>::type*
TrackNew( typename extract<T>::type* ptr,
const char* file, int line )
{
return TrackNewImpl<T>::TrackNew( *this,
ptr, file, line );
}
I need to explicitly specify the template parameter to be able to
distinguish between the object and the array form of new.
--
Matthias Hofmann
Anvil-Soft, CEO
http://www.anvil-soft.com - The Creators of Toilet Tycoon
http://www.anvil-soft.de - Die Macher des Klomanagers
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]