N
Nadav
Hi,
I am trying to manually call a constructor of a template argument, the
compiler returns “error C2039: ‘T’ : is not a member...â€
How can I manually call the constructor of a template argument?
Please note that I cannot use the ‘new’ operator ( as long as it allocates
memory ), see the following code snnipet as an example of what I am trying to
do.
class HEADER {
LONG lStam;
HEADER() : lStam(0) {}
};
template< typename T >
class CMyTest
{
protected:
CMyTest();
~CMyTest();
typename T m_pObjects[0];
public:
static HRESULT CreateInstance(IN int iObjCount, OUT CMyTest** ppObj) {
*ppObj = (CMyTest*)malloc(sizeof(CMyTest) + sizeof(T) * iObjCount);
if(0 == *ppObj)
return E_OUTOFMEMORY;
(*ppObj)->CMyTest::CMyTest();// Works, calls the constructor
for(int i = 0; i < iObjCount; i++)
(*ppObj)->m_pObjects[0].T::T();// error C2039: 'T' : is not a member of
'HEADER'
}
};
int _tmain(int argc, _TCHAR* argv[])
{
CMyTest<HEADER>* pTest;
CMyTest<HEADER>::CreateInstance(10, &pTest);
}
The above code doesn’t have any practical meaning, it’s only goal is to
demonstrate the problem I am describing here
I am trying to manually call a constructor of a template argument, the
compiler returns “error C2039: ‘T’ : is not a member...â€
How can I manually call the constructor of a template argument?
Please note that I cannot use the ‘new’ operator ( as long as it allocates
memory ), see the following code snnipet as an example of what I am trying to
do.
class HEADER {
LONG lStam;
HEADER() : lStam(0) {}
};
template< typename T >
class CMyTest
{
protected:
CMyTest();
~CMyTest();
typename T m_pObjects[0];
public:
static HRESULT CreateInstance(IN int iObjCount, OUT CMyTest** ppObj) {
*ppObj = (CMyTest*)malloc(sizeof(CMyTest) + sizeof(T) * iObjCount);
if(0 == *ppObj)
return E_OUTOFMEMORY;
(*ppObj)->CMyTest::CMyTest();// Works, calls the constructor
for(int i = 0; i < iObjCount; i++)
(*ppObj)->m_pObjects[0].T::T();// error C2039: 'T' : is not a member of
'HEADER'
}
};
int _tmain(int argc, _TCHAR* argv[])
{
CMyTest<HEADER>* pTest;
CMyTest<HEADER>::CreateInstance(10, &pTest);
}
The above code doesn’t have any practical meaning, it’s only goal is to
demonstrate the problem I am describing here