| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 440 人关注过本帖
标题:求助vc++程序问题
只看楼主 加入收藏
Ivorning
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-10-13
收藏
 问题点数:0 回复次数:1 
求助vc++程序问题

template<class T> class Chain<T>
template<class T>
class ChainNode{ //节点类
friend class Chain<T>;
private:
T data;
ChainNode<T> *link;
};
template<class T>
class Chain{
public:
Chain(){first=0;}
~Chain();
bool IsEmpty(){return first==0;}
int length()const;
void InsertHead(const T&x);
Chain<T>&Delete(int k,T&x);
int Search(const T&x)const;
void Output()const;
private:
ChainNode<T> *first;
};
template<class T>
Chain<T>::~Chain(){
ChainNode<T> *next;
while(first){
next=first->link;
delete first;
first=next;}
}
template<class T>
int Chain<T>::length()const{
int n=0;
ChainNode<T> *current=first;
while(current){
current=current->link;
n++;
}
return n;
}
template<class T>
void Chain<T>::InsertHead(const T&x){
ChainNode<T> *first1=new ChainNode<T>;
first1->data=x;
first1->link=first;
first=first1;
}
template<class T>
Chain<T>&Chain<T>::Delete(int k,const T&x){
ChainNode<T> *current=first;
ChainNode<T> *previous=0;
for(int i=0;i<k;i++){
previous=current;
current=current->link;
}
x=current->data;
previous->link=current->link;
delete current;
return *this;
}
template<class T>
int Chain<T>::Search(const T&x)const{
ChainNode<T> *current=first;
int n1;
while(current->data!=x||current){
current=current->link;
n1++;
}
if(current){return n1;}
else return 0;//not find
}
template<class T>
void Chain<T>::Output()const{
ChainNode<T> *current=first;
while(current){cout<<current->data<<" ";}
cout<<endl;
}


主程序如下
#include<iostream.h>
#include"chain.h"
void main(){
Chain<int> c();
cout<<"请输入数字";
c.InsertHead(5);
c.InsertHead(6);
c.Output();
}
编译器报错如下
Compiling...
cn.cpp
d:\工具\visurl c++\msdev98\myprojects\lianbiao\chain.h(1) : error C2143: syntax error : missing ';' before '<'
d:\工具\visurl c++\msdev98\myprojects\lianbiao\chain.h(1) : error C2143: syntax error : missing ';' before '<'
d:\工具\visurl c++\msdev98\myprojects\lianbiao\chain.h(3) : error C2143: syntax error : missing ';' before '{'
d:\工具\visurl c++\msdev98\myprojects\lianbiao\chain.h(3) : error C2447: missing function header (old-style formal list?)
d:\工具\visurl c++\msdev98\myprojects\lianbiao\chain.h(21) : error C2143: syntax error : missing ';' before '<'
d:\工具\visurl c++\msdev98\myprojects\lianbiao\chain.h(22) : see reference to class template instantiation 'Chain<T>' being compiled
d:\工具\visurl c++\msdev98\myprojects\lianbiao\chain.h(21) : error C2501: 'ChainNode' : missing storage-class or type specifiers
d:\工具\visurl c++\msdev98\myprojects\lianbiao\chain.h(22) : see reference to class template instantiation 'Chain<T>' being compiled
d:\工具\visurl c++\msdev98\myprojects\lianbiao\chain.h(21) : error C2059: syntax error : '<'
d:\工具\visurl c++\msdev98\myprojects\lianbiao\chain.h(22) : see reference to class template instantiation 'Chain<T>' being compiled
d:\工具\visurl c++\msdev98\myprojects\lianbiao\chain.h(21) : error C2238: unexpected token(s) preceding ';'
d:\工具\visurl c++\msdev98\myprojects\lianbiao\chain.h(22) : see reference to class template instantiation 'Chain<T>' being compiled
d:\工具\visurl c++\msdev98\myprojects\lianbiao\chain.h(60) : error C2244: 'Chain<T>::Delete' : unable to resolve function overload
d:\工具\visurl c++\msdev98\myprojects\lianbiao\chain.h(61) : error C2954: template definitions cannot nest
d:\工具\visurl c++\msdev98\myprojects\lianbiao\cn.cpp(6) : error C2228: left of '.InsertHead' must have class/struct/union type
d:\工具\visurl c++\msdev98\myprojects\lianbiao\cn.cpp(7) : error C2228: left of '.InsertHead' must have class/struct/union type
执行 cl.exe 时出错.

lianbiao.exe - 1 error(s), 0 warning(s)



这是怎么回事啊 请高手指点 小弟感激不尽

搜索更多相关主题的帖子: Chain class const int 
2007-10-30 10:50
pfan88
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-10-18
收藏
得分:0 

太长了,晕

2007-10-30 13:37
快速回复:求助vc++程序问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.044581 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved