View Full Version : C++ Related Classes Problems
Trinithis
10-15-2007, 01:52 AM
I can't get the following code to compile:
class Foo {
public:
Bar* bar;
Foo() {
bar = NULL;
}
};
class Bar {
public:
Foo* foo;
Bar() {
foo = NULL;
}
};
How can I achieve this effect?
You need to use a forward declaration:class Bar;
class Foo {
public:
Bar* bar;
Foo() {
bar = 0;
}
};
class Bar {
public:
Foo* foo;
Bar() {
foo = 0;
}
};
Trinithis
10-15-2007, 02:03 AM
Thanks. I tried that a first and thought I was doing something wrong because it didn't work. As it turns out, I am working with generics, and I needed a little extra:
template <class T> class Iterator;
Seems to work. For now . . .
vBulletin® v3.8.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.