i have trouble to define a static member in a template, and i search from google, but didn't find any similar case, my case is a little complex, i paste the code below.
code in xxx.h
Code:
template <class T> class FreeListManager
{
public:
FreeListManager(int s=0);
~FreeListManager();
T* acquire();
void release(T*);
protected:
static list<T*> freeList;
static list<T*> usedList;
// We have size parameters separated from list, since
// size() function of list container is inefficient.
};
code in xxx.cpp
Code:
template<class T> list<T*>
FreeListMaager<T>::freeList;
template<class T> list<T*>
FreeListManager<T>::usedList;
//there is no T defined
for the xxx.cpp file, actually, it is confused me a lot, and it seem to be not what i want, what is the type of the entry in freeList like? i got coredump when use the freeList.pushback. and i ever tried to define the two list static member like
Code:
template<class CLASSA> list<CLASSA*>
FreeListManager<CLASSA>::freeList;
template<class CLASSA> list<CLASSA*>
FreeListManager<CLASSA>::usedList;
template<class CLASSB> list<CLASSB*>
FreeListManager<CLASSB>::freeList;
template<class CLASSB> list<CLASSB*>
FreeListManager<CLASSB>::usedList;
i got redefinition for freeList and usedList error.
i was told FreeListManager<CLASSA> and FreeListManager<CLASSB> are totally two different class, why does the redefinition error come out?
i also try
Code:
list<CLASSA*> FreeListManager<CLASSA>::freeList;
list<CLASSA*> FreeListManager<CLASSA>::usedList;
list<CLASSB*> FreeListManager<CLASSB>::freeList;
list<CLASSB*> FreeListManager<CLASSB>::usedList;
i got too few template-parameter-lists error, the code can be compiled on gcc earlier version,
can someone help me, really appreciate your help.
denny