What wrong with this code?

Hi.

it doesn't compile...

template <typename T>
class CObjectsPool
{
public:
// static CObjectsPool<T>* GetInstance();

protected:
CObjectsPool();
~CObjectsPool();

private:
static CObjectsPool<T>* m_pInst;
};
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////

template <typename T>
CObjectsPool<T>* CObjectsPool<T>::m_pInst = NULL;

template <typename T>
CObjectsPool<T>::CObjectsPool()
{
}

template <typename T>
CObjectsPool<T>::~CObjectsPool()
{
}

those are the errors:

SBPMsgResponse.h(85) : error C2059: syntax error : '<'
SBPMsgResponse.h(85) : error C2238: unexpected token(s) preceding ';'
Pool.h(44) : error C2989: 'CObjectsPool' : template class has already been defined as
onTypes\SBPMsgResponse.h(26) : see declaration of 'CObjectsPool'
Pool.h(32) : error C3857: 'CObjectsPool': multiple template parameter lists are not al
Pool.h(49) : error C2988: unrecognizable template declaration/definition
Pool.h(49) : error C2059: syntax error : '<'
Pool.h(49) : error C2039: 'm_pInst' : is not a member of 'operator``global namespace''
Pool.h(53) : error C2143: syntax error : missing ';' before '{'
Pool.h(53) : error C2447: '{' : missing function header (old-style formal list?)
Pool.h(57) : error C2988: unrecognizable template declaration/definition
Pool.h(57) : error C2059: syntax error : '<'
Pool.h(57) : error C2588: '::~CObjectsPool' : illegal global destructor
Pool.h(57) : fatal error C1903: unable to recover from previous error(s); stopping com

SBPMsgResponse.h(85) : error C2059: syntax error : '<'
SBPMsgResponse.h(85) : error C2238: unexpected token(s) preceding ';'

10x. alot !
[2163 byte] By [Shvalb] at [2007-11-20 10:07:00]
# 1 Re: What wrong with this code?
Templated classes must have the definitions of their members inline, not in a seperate .cpp file.

Try

template <typename T>
class CObjectsPool
{
public:
static CObjectsPool<T>* GetInstance()
{
static CObjectsPool<T> instance;
return &instance;
}

protected:
CObjectsPool()
{
}

~CObjectsPool()
{
}
};

I believe this will do what you want. I don't think they can have static member variables either - hence the above in GetInstance - but I'm probably wrong on this.

Darwen.
darwen at 2007-11-11 4:03:25 >
# 2 Re: What wrong with this code?
welp, all the code I wrote is in .h file.

It is a static GetInstance and there is no problem with it.

I found my problem and it wasn't related to this code - this code is valid.

Thanks alot mate!
Shvalb at 2007-11-11 4:04:26 >