template <class T, class FPTR = void (void *)>
class CSmartPtr
{
public :
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
CSmartPtr()
{
m_TData = NULL;
m_deleter = NULL;
}
CSmartPtr(T* TData)
{
m_TData = TData;
m_deleter = NULL;
}
CSmartPtr(T* TData, FPTR *deleter)
{
m_TData = TData;
m_deleter = deleter;
}
~CSmartPtr()
{
if (NULL == m_deleter)
{
delete m_TData;
}
else
{
m_deleter(m_TData);
}
}
T *const operator-> () const
{
return m_TData;
}
//-----------------------------------------------------------------------
// Getter methods
//-----------------------------------------------------------------------
T *const get() const
{
return m_TData;
}
void reset(T* TData)
{
if (NULL != m_TData)
{
if (NULL == m_deleter)
{
delete m_TData;
}
else
{
m_deleter(m_TData);
}
}
m_TData = TData;
}
private :
// -----------------------------------------------------------------------
// Private data members
//
// fUnicodeForm
// This is the Unicode XMLCh format of the string.
// -----------------------------------------------------------------------
T *m_TData;
FPTR *m_deleter;
};
int main( void )
{
CSmartPtr<BYTE> apbySrcBuff; // This doesnt work.
CSmartPtr<BYTE, (void) (void *)> apbySrcBuff; // This works.
getchar();
return TRUE;
}
我完全是新手templates
,而且我从几个小时开始就被上述问题困扰。试图自己解决它,但没有成功。
错误是Error 1 error C2064: term does not evaluate to a function taking 1 arguments
该行是
m_deleter(m_TData);