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