比较莫名的C2059和C2334

JPcensus 2010-09-13 09:41:58
#include<iostream>
using namespace std;
#include"Metro.h"
float weights[2]={0.0,0.0,0.0};
string routes[2];
string change[2];
int count[2]={0,0};
int Count[2]={0,0);
在第四行,第七行,第八行都分别出现了
error C2059: syntax error :{
error C2334: unexpected token(s) preceding '{'; skipping apparent function body
我查了Msdn,说C2334是只有在另一个错误之后而且是在类内定义成员函数是才会出现的。但这是在初始化变量而且是在类外呀,我实在不知道为什么。
还有我定义构造函数的时候出现了如下错误,最后居然搞了个错误太多无法继续编译出来:
C2838:illegal qualified name in member declaration
定义就是这个:
Metro::Metro(int numofarc,int numofvertex){
numofarc=0;
numofvertex=0
int t,h;
int w;
string v[Vertexmax];
vertextable=new VertexNode;
ifile.open("metro.txt",ios::in);
if(!ifile) return -1;
else{
for(int i=0;i<=55;i++){
if(ifile.eof()!=1) ifile>>v[i];
Insertvertex(v[i]);
}
for(i=0;i<=110;i++){
ifile>>h>>t>>w;
InsertArc(h,t,w);
}
ifile.close();
}
ifile.clear(0);
}
头文件Metro.h如下:
#include<string>
#include<fstream>
using namespace std;
#define Maxvertex 100;
struct ArcNode{
int Adjex;
int Weight;
ArcNode *Next;
};
struct VertexNode{
string Station;
ArcNode *Firstarc;
};

struct Stack{
int top;
int *elements;
int stacksize;
class Metro{
VertexNode *vertextable;
int numofarc;
int numofvertex;
ifstream ifile;
public:
Metro(int numofarc,int numofvertex);
~Metro();
void Initstack(Stack &s);
void InsertVertex(string s);
void InsertArc(int tail,int head,int w);
void DFSearch(string b,string t);
int Getnextneighbor(int v);
int Getnextneighbor(int v,int w);
void Push(Stack &s,int e);
void Pop(Stack &s,int e);
void Shortest();
void MinExchange();
int IsEmpty(Stack &s);
int Locate(string u);
float GetWeight(int t,int h);
};








...全文
624 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
JPcensus 2010-09-14
  • 打赏
  • 举报
回复
我已经知道错在哪儿了。struct少了半边括号。
赵4老师 2010-09-14
  • 打赏
  • 举报
回复
偶遇到类似问题都是用
“每次用/*...*/注释掉不同部分再重新编译,直到定位到具体语法出错的位置。”
的方法解决的。
JPcensus 2010-09-13
  • 打赏
  • 举报
回复
我已经改了,不行……
Eleven 2010-09-13
  • 打赏
  • 举报
回复
float weights[2]={0.0,0.0,0.0};
溢出了。。。
JPcensus 2010-09-13
  • 打赏
  • 举报
回复
依然不行…………谁能告诉我这是为什么?
赵4老师 2010-09-13
  • 打赏
  • 举报
回复
试试
#include<iostream>
using namespace std;
#include "Metro.h"
;//---------------------------

float weights[2]={0.0,0.0};
string routes[2];
string change[2];
int count[2]={0,0};
int Count[2]={0,0};
JPcensus 2010-09-13
  • 打赏
  • 举报
回复
另外int Count里的那个符号错误,也就是把}弄成),我早就改了。似乎别人的程序有这种错误都是因为在类内给数据成员赋初值,可那个明显不是数据成员啊……
JPcensus 2010-09-13
  • 打赏
  • 举报
回复
我改成了两个还是不行。
冻结 2010-09-13
  • 打赏
  • 举报
回复
C++错误要关注第一个。
float weights[2]={0.0,0.0,0.0};
给两个元素的数组赋了三个值。

65,187

社区成员

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

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