#include
template class list;
template
class listnode
{
friend class list;
public:
listnode(T);
listnode(){info=0;next=0;}
private:
listnode *next;
T info;
};
template
listnode::listnode(T inf)
{
info=inf; next=0;
}
template
class list
{
private:
listnode* head;
listnode* tail;
public:
list();
~list();
void insertatfront(T&);
void insertatback(T&);
void deletefromfront(T&);
void deletefromback(T&);
};
template
list::list(){ tail=0;head->next=tail;}
template
void list::insertatfront(T &info)
{
listnode* temp=new listnode(info);
temp->next=head->next;
head->next=temp;
}
template
void list::insertatback(T &info)
{
listnode *tempt=new listnode(info);
tail->next=tempt;
tail=tempt;
}
template
list::~list()
{
listnode* tempt=head->next;
listnode* current=0;
cout<<" destroying......."< while(tempt!=0)
{
current=tempt;
cout<info<<" ";
delete current;
tempt=tempt->next;
}
}
int main()
{
list list1; int a;
for(int i=0;i<5;i++)
list1.insertatfront(i);
return 0;
}
错误提示:Configuration: list - Win32 Debug--------------------
Compiling...
list.cpp
G:\list.cpp(82) : warning C4101: 'a' : unreferenced local variable
G:\list.cpp(48) : error C2955: 'listnode' : use of class template requires template argument list
G:\list.cpp(15) : see declaration of 'listnode'
G:\list.cpp(88) : while compiling class-template member function 'void __thiscall list::insertatfront(int &)'
G:\list.cpp(48) : error C2955: 'listnode' : use of class template requires template argument list
G:\list.cpp(15) : see declaration of 'listnode'
G:\list.cpp(88) : while compiling class-template member function 'void __thiscall list::insertatfront(int &)'
G:\list.cpp(48) : error C2514: 'listnode' : class has no constructors
G:\list.cpp(15) : see declaration of 'listnode'
G:\list.cpp(88) : while compiling class-template member function 'void __thiscall list::insertatfront(int &)'
Error executing cl.exe.
list.obj - 3 error(s), 1 warning(s)
小弟我弄了将近3小时就是不知道哪里出了问题,希望高手指点一二,在下感激不尽!
--------------------next---------------------
#include
using namespace std;
template class list;
template
class listnode
{
friend class list;
public:
listnode(T);
listnode(){info=0;next=0;}
private:
listnode *next;
T info;
};
template
listnode::listnode(T inf)
{
info=inf; next=0;
}
template
class list
{
private:
listnode* head;
listnode* tail;
public:
list();
~list();
void insertatfront(T&);
void insertatback(T&);
void deletefromfront(T&);
void deletefromback(T&);
};
template
list::list(){ tail=NULL;head = NULL;}
template
void list::insertatfront(T &info)
{
listnode* temp=new listnode(info);
if( NULL == head)
{
head = temp;
head->next = NULL;
}
else
{
temp->next=head;
head=temp;
}
}
template
void list::insertatback(T &info)
{
listnode *tempt=new listnode(info);
tail->next=tempt;
tail=tempt;
}
template
list::~list()
{
listnode* tempt=head;
listnode* current=0;
cout<<"destroying......."<while(tempt != NULL)
{
current=tempt;
cout<info<<" "<tempt=tempt->next;
delete current;
}
}
int main()
{
list list1; int a;
for(int i=0;i<5;i++)
list1.insertatfront(i);
return 0;
}
--------------------next---------------------
阅读(1684) | 评论(0) | 转发(0) |