[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how do you compile 2 classes that include each other?
From: |
Frank Buss |
Subject: |
Re: how do you compile 2 classes that include each other? |
Date: |
Wed, 17 Apr 2002 21:13:27 +0200 |
briforge wrote...
> When I compile the Edge2 class, I get this error:
>
> In file included from Edge2.cpp:6:
> Vertex2.cpp:18: `Edge2' was not declared in this scope
> Vertex2.cpp:18: parse error before `>'
Don't mix declaration and implementation. With forward declaration you can
do the following, if you only use pointers as member variables and use
references as arguments. I have no answer what to do, if you have in both
classes member variables of the other class, which are not pointers :o) ,
any ideas?
For your case the following should do it, I hope:
Edge.h:
#ifndef EDGE_H
#define EDGE_H
class Vertex;
class Edge
{
...
Edge(const Vertex& startV...);
...
};
#endif
Vertex.h:
#ifndef VERTEX_H
#define VERTEX_H
class Edge;
class Vertex
{
...
vector<Edge*> edges;
...
};
#endif
Edge.cpp:
#include "Edge.h"
#include "Vertex.h"
...
Vertex.cpp:
#include "Edge.h"
#include "Vertex.h"
...
Regards,
Frank
* Programmers are tools for converting caffeine into code.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: how do you compile 2 classes that include each other?,
Frank Buss <=