Topic: Troule with Interdependant classes
Author: Wil Evers <bouncer@dev.null>
Date: 08 Dec 00 00:31:11 GMT Raw View
In article <90nr64$45i$1@nnrp1.deja.com>, Rene Nyffenegger wrote:
> I am getting stuck with
>
>
> class A {
> B _b;
> };
>
> class B {
> std::vector<A> GetSomeAs();
> };
>
> I cant't think of way using forward declarations to solve that!
> If someone can, please let me know.
If your compiler doesn't accept this, then forward-declare class B
before class A, and declare _b to be a pointer to a B.
However, I *think* it should be possible to get what you're after by
writing:
#include <vector>
class A;
class B {
std::vector<A> GetSomeAs();
};
class A {
B _b;
};
In fact, it would be very useful to be able to declare recursive data
structures like:
#include <vector>
struct Node {
int data;
std::vector <Node> children;
};
CORBA IDL allows something like this; I'm not sure the C++ standard
allows it too. Anyone? [cross-posted to comp.std.c++]
- Wil
--
Wil Evers, DOOSYS IT Consultants, Maarssen, Holland
[Wil underscore Evers at doosys dot com]
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]