Re: Workaround for partial specialization wanted
"Matthias Hofmann" <hofmann@anvil-soft.com> schrieb im Newsbeitrag
news:5po7pgFscksfU1@mid.individual.net...
Now my code looks like this:
#include <iostream>
#include "remove_extent.hpp"
template <class T>
T* TrackNew( T* ptr, const char* file, int line, int )
{
std::cout << "Tracking object allocation" << std::endl;
return ptr;
};
template <class T>
boost::remove_extent<T>::type* TrackNew( boost::remove_extent<T>::type*
ptr,
const char* file, int line, ... )
{
std::cout << "Tracking array allocation" << std::endl;
return ptr;
}
#define NEW( T ) TrackNew<T>( new T, __FILE__, __LINE__, 0 )
int main()
{
int* p1 = NEW( int );
delete p1;
int* p2 = NEW( int[64] );
delete [] p2;
return 0;
}
Unfortunately this does not help me as much as I thought it would, because
in my actual code, TrackNew() is a member function template, and while the
above code does not cause any problems, my compiler chokes on the following:
template <class T> T* f( T* ptr )
{
return ptr;
}
struct X
{
template <class T> T* f( T* ptr )
{
return ptr;
}
};
int main()
{
int i;
// Does not cause any problems.
int* p = f<int>( &i );
X x;
// error C2062: type 'int' unexpected
p = x.f<int>( &int );
return 0;
}
Does anyone happen to know a workaround for this? If yes, then I might give
it yet another try...
--
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! ]