You guys/gals are saying the same thing . . . .
I didn't think you could declare references based on forward declarations -- until I tried it. (Deja vu . . . .)
Code:
#include <iostream>
class b;
class a { class b &bb; };
class b { class a &aa; };
int main() { return 0; }
On the other hand, this does not work:
Code:
#include <iostream>
class b;
class a {
public:
class b &bb;
void set() { std::cout << "a::set()\n"; }
void setother() { bb.set(); }
};
class b {
public:
class a &aa;
void set() { std::cout << "b::set()\n"; }
void setother() { aa.set(); }
};
int main() {
a aa;
b bb;
aa.set();
aa.setother();
bb.set();
bb.setother();
return 0;
}
(Sorry, Elysia.)
I guess it follows the same principles as declaring pointers to forward-declared objects: you can do it, but you can't access anything inside the object without having a full declaration.