syntax error : missing ';' before '*'
I am getting a syntax error : missing ';' before '*' in my code. I have written 6 different classes, and all of them link to at least one other class.
Here are my class names:
Vertex, VertList, Edge, EdgeList, AdjList, and Graph.
I have checked every class about 5 times for a missing semicolon (yes I checked the ones at the end of the class declaration, too)
So it is either being extremely elusive or its something else.
Is this a problem:
Vertex includes EdgeList
EdgeList includes Edge
Edge includes Vertex
Thats the only thing I can think of, is that it is somehow freaking visual studio out.
I would post my code, but I don't think you want to go through 6 classes and their definitions.
Re: syntax error : missing ';' before '*'
Most likely, you forgot the semicolon after your class definition. I miss it every time :P
Code:
classdef{
public:
classdef(void);
};
Re: syntax error : missing ';' before '*'
No, no, thats what I meant to say. I've checked those and every other line of code several times.
Re: syntax error : missing ';' before '*'
You've probably got an include cycle. With proper include guards on the classes, an include cycle means
A gets pasted inside C gets pasted inside B gets pasted inside A
where "gets pasted inside" is the intuitive way to think of what a #include really does.
Except, since the final A's include guard has already been defined, the innermost A actually has empty contents! Hence the error.
The solution is to break the include cycle by, for at least one of the classes, removing the #include and relying solely on forward-declarations in the header file. The source file can still have the include, naturally.
In general, headers should limit their includes in favor of forward-declares as much as possible, while source files should go nuts on the includes.
Re: syntax error : missing ';' before '*'
Quote:
Originally Posted by sneakyarab
Vertex includes EdgeList
EdgeList includes Edge
Edge includes Vertex
Quote:
Originally Posted by Lindley
A gets pasted inside C gets pasted inside B gets pasted inside A
:thumb:
Viggy
Re: syntax error : missing ';' before '*'
OK that makes sense but I'm not really sure how I can do this without the includes :(
Re: syntax error : missing ';' before '*'
Paste one of the headers here. Maybe we can suggest a way.
Re: syntax error : missing ';' before '*'
OK here are the headers that are in the cycle:
#ifndef VERTEX_H
#define VERTEX_H
#include <iostream>
#include "EdgeList.h"
using namespace std;
class Vertex{
char label;
Vertex* next;
int inEdges, outEdges;
EdgeList* inEdgeP;
EdgeList* outEdgeP;
public:
Vertex();
Vertex(char x, Vertex* n);
char getLabel();
void setLabel(char x);
void setNext(Vertex* x);
Vertex* getNext();
void addIn();
void addOut();
void subIn();
void subOut();
int getIn();
int getOut();
void setInP(EdgeList* e);
void setOutP(EdgeList* e);
EdgeList* getInP();
EdgeList* getOutP();
};
#endif
--------------------------------------------------------------------------
#ifndef EDGELIST_H
#define EDGELIST_H
#include "Edge.h"
using namespace std;
class EdgeList{
Edge* start;
Edge* next;
int n;
public:
EdgeList();
EdgeList(Edge* s, Edge* n);
Edge* getNext();
void setNext(Edge* e);
int size();
Edge* getStart();
};
#endif
--------------------------------------------------------------------------
#ifndef EDGE_H
#define EDGE_H
#include "Vertex.h"
using namespace std;
class Edge{
Vertex* start;
Vertex* finish;
Edge* next;
int label;
public:
Edge();
Edge(Vertex* s, Vertex* f, int label, Edge* next);
void setStart(Vertex* s);
Vertex* getStart();
void setFinish(Vertex* f);
Vertex* getFinish();
void setLabel(int x);
int getLabel();
Edge* getNext();
void setNext(Edge* e);
};
#endif
Re: syntax error : missing ';' before '*'
Next time, code tags.
Fortunately for you, your design lends itself to solving this easily. Simply replace the relevant
Code:
#include "Filename.h"
with
in all three files.
Re: syntax error : missing ';' before '*'
It didnt seem to like that either, I switched around using class and include between all the files and couldnt get it working right at all. I changed the Edge class to just have character values where the vertexes were, and have been changing code accordingly. Im down from 200+ errors to less than 10, fixable errors now.
Re: syntax error : missing ';' before '*'
I noticed that you have using namespace std; in your header files, that can cause problems as well. using namespace whatever; should only be in your implementation files.
Similarly, you have #include <iostream> in your Vertex.h but do not make use of it.