比较莫名的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);
};








...全文
794 9 打赏 收藏 转发到动态 举报
写回复
用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};
给两个元素的数组赋了三个值。
代码下载链接: https://pan.quark.cn/s/3379ee0243ef 在IAR调试环节中,使用者或许会遭遇各式各样的故障,这些故障可能波及编译、链接以及执行时的情形。下面列出了部分常见的IAR调试故障及其应对措施: 1. **头文件中全局变量的声明**:IAR链接器不允许在头文件里声明全局变量,但容许多个源文件同时引用同一变量。一旦出现此类状况,应将全局变量声明为`extern`类型。例如,错误信息`Error[e27]: Entry "tagData" redefined`可以通过在头文件中附加`extern`关键字来纠正。 2. **隐式指定的函数**:`Error[Pe223]: function "assert_param" declared implicitly`指出函数`assert_param`未被显式地定义。务必确保包含了适宜的头文件,比如`stm32f10x_conf.h`,该文件内含了该函数的原型。倘若已包含,则可能是库文件版本不匹配或项目配置存在疑惑。 3. **无原型指引的函数**:`Error[Pa045]: function "assert_param" has no prototype`与上述情形相似,意指函数缺乏相应的原型声明。仔细核对相关头文件,保证它们在使用前已被适当地引入。 4. **标识符未获定义**:`Error[Pe020]: identifier "RCC_APB2Periph_GPIOC" is undefined`表明某个标识符的定义未能找到,这通常源于未引入必要的头文件。在此情形下,需包含`stm32f10x_rcc.h`。 5. **宏定义与编译文件的矛盾**:若尝试调整设备配置,如从STM...

65,211

社区成员

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

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