代码找错

wqwqy123 2017-04-22 07:17:47
错误为zhouliu1.cc:15:12: error: expected ‘)’ before ‘a’
zhouliu1.cc:16:2: error: invalid use of destructor ‘~ALGraph’ as a type
zhouliu1.cc:18:3: error: invalid use of template-name ‘VertexNode’ without an argument list
zhouliu1.cc:21:17: error: expected constructor, destructor, or type conversion before ‘(’ token
麻烦大家帮我看一下,谢谢啦


#include <iostream>
using namespace std;
struct ArcNode
{int adjvex;
ArcNode*next;
};
template <class T>
struct VertexNode
{T vertex;
ArcNode*firstedge;
};
const int MaxSize=10;
class ALGraph
{public:
ALGraph(T a[],int n,int e);
~ALGraph;
private:
VertexNode adjlist[MaxSize];
int vertexNum,arcNum;
};
ALGraph::ALGraph(T a[],int n,int e)
{
vertexNum=n;arcNum=e;
for(i=0;i<vertexNum;i++)
{adjlist[i].vertex=a[i];
adjlist[i].firstedge=NULL;
}
for(k=0;k<arcNum;k++)
{cin>>i>>j;
s=new ArcNode;s->adjvex=j;
s->next=adjlist[i].firstedge;
adjlist[i].firstedge=s;
}
}
int main()
{int a[6]={1,2,3,4,5,6};
ALGraph(a,6,5);
return 0;
}
...全文
295 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2017-04-26
  • 打赏
  • 举报
回复
偶遇到类似问题都是用 “每次用/*...*/注释掉不同部分再重新编译,直到定位到具体语法出错的位置。” 的方法解决的。
wqwqy123 2017-04-25
  • 打赏
  • 举报
回复
你好,我改了一下,不过还有这两个错误,不知道是什么意思,菜鸟一枚,麻烦指教一下啦,非常感谢, zhouliu1.cc:19:3: error: invalid use of template-name ‘VertexNode’ without an argument list zhouliu1.cc:23:1: error: invalid use of template-name ‘ALGraph’ without an argument list
flying_music 2017-04-22
  • 打赏
  • 举报
回复
语法错没了,你去看看逻辑吧,还不对呢

#include <iostream>

using namespace std;

struct ArcNode
{
	int adjvex;
	ArcNode *next;
};
template <typename T>
struct VertexNode
{
	T vertex;
	ArcNode *firstedge;
};
const int MaxSize=10; 

template <class T> //这一句
class ALGraph
{
public:
	ALGraph(T a[],int n,int e);
	~ALGraph(){}//这一句
private:
	VertexNode<T> adjlist[MaxSize];
	int vertexNum,arcNum;
};

template <class T> //这一句
ALGraph<T>::ALGraph(T a[],int n,int e) //这一句
{
	vertexNum=n;arcNum=e;
	int i, j, k;//这一句
	for(i=0;i<vertexNum;i++)
	{
		adjlist[i].vertex = a[i];
		adjlist[i].firstedge=NULL;
	}
	for(k=0;k<arcNum;k++)
	{cin>>i>>j;
	ArcNode *s=new ArcNode;s->adjvex=j;//这一句
	s->next=adjlist[i].firstedge;
	adjlist[i].firstedge=s;
	}
}
int main()
{
	int a[6]={1,2,3,4,5,6};
	ALGraph<int> (a,6,5); //这一句
	return 0;
}

65,179

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧