Class pointer in another class pointer

I implement graph class like this :
#ifndef VERTEX_H_
#define VERTEX_H_
class Vertex {
public:
Vertex* nextVertex;
Arc * _arc;
int data;
int inDegree;
int outDegree;
int processed; // used for DFS & BrFS
bool inResult; // used for finding spanning tree
Vertex(int dataKey);
Vertex(); //default: dataKey = 0
};
class Arc {
Vertex* dest;
Arc* nextArc;
float weight;
Arc(float weight);
Arc(); //default: weight = 0
};

#endif VERTEX_H_

Why doesn't it work ?
fail in : Arc * _arc; ISO C++ forbids declaration of `Arc' with no type

Please help me.
Thank for all.
i think because in the vertex class you have arc the this type is yet not defined and compiler knows nothing about the arc type.
before the class Vertex just declare class Arc with just this line

class Arc ;

I think it should work. Just try it
when i add class Arc; before this code. It has another problem recurse definition 2 class Arc and Vertex;
You probably added class Arc before de include guard (the #ifndef....#define...#endif part). You have to add the code inside the guard, between #define VERTEX_H_ and class Vertex..., or it will be define more than once, as the compiler error is telling.
I think it will never work for recursive adding the class in one another ...
Correct me if i am wrong .
bluecoder wrote:
I think it will never work for recursive adding the class in one another...

That's correct. But Vertex stores a pointer to an Arc, not an Arc object. So the compiler doesn't need to know what composes an Arc, since all pointers are the same, no matter what they point to.
Topic archived. No new replies allowed.