On (23 Jul 97) Christian S. Pedersen wrote to All...
CS> Hello All.
CS> I want to define two classes like the following:
CS> class A
CS> {
CS> A(int a) { };
CS> B func1() { return B(1); };
CS> }
CS> class B
CS> {
CS> B(int a) { };
CS> A func2() { return A(1); };
CS> }
CS> two classes which each contains a function which return a instance of
CS> the other class. I get a "typename expected"-error in class A. I
CS> believe I have to use the "typename" keyword, but I can't get it to
CS> work.
Nope - you just have to do a forward declaration that B is the name of a
class before you try to use it as a return type:
class B;
class A {
B func1() { return B(1); }
};
class B {
B(int a) { /* ... */ }
};
should do the trick.
Later,
Jerry.
... The Universe is a figment of its own imagination.
--- PPoint 1.90
---------------
* Origin: Point Pointedly Pointless (1:128/166.5)
|