I am creating a linked list with self referential class in C++ and I want to have a static pointer of the type Item (Item is the class name) named "startPointer" so that when i call my static member function "free" , it can free up the memory by using Item::startPointer but i am getting an error(shown after code). Pls Help,
class Item
{
public:
std::string name;
int row,column;
int fileType;
Item *ptr;
static Item *startPointer;
void setNextPointer(Item* ptr)
{
ptr=ptr;
}
Item *getNextPointer()
{
return ptr;
}
static void free()
{
Item *p,*temp;
p=startPointer;
while(p!=NULL)
{
temp=p;
p=p->getNextPointer();
delete temp;
}
}
};
cube.o:cube.cpp:(.text$_ZN4Item4freeEv[Item::free()]+0x8): undefined reference to `Item::startPointer'
collect2: ld returned 1 exit status
mingw32-make.exe: *** [cube.exe] Error 1
Execution terminated
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…