CS> two classes which each contains a function which return a
CS> instance of the other class. I get a "typename expected"-
CS> error in class A. I believe I have use the "typename"
CS> keyword, but I can't get it to work.
This is called a circular dependency. :)
The following code should compile and run with no errors:
#include
class TypeB;
/* This previous line does nothing but notify the compiler
that there is, in fact, a valid class TypeB.
*/
class TypeA
{
public:
void A(TypeB &a) { b = &a; };
TypeB *func1() { return b; };
private:
TypeB *b;
};
class TypeB
{
public:
void A(TypeA &a) { b = &a; };
TypeA *func1() { return b; };
private:
TypeA *b;
};
int main(void)
{
TypeA Acls;
TypeB Bcls;
Acls.A(Bcls);
Bcls.A(Acls);
cout << "Acls "
<< ((&Acls == Bcls.func1()) ? "==" : "!=")
<< " Bcls.func1()" << endl;
cout << "Bcls "
<< ((&Bcls == Acls.func1()) ? "==" : "!=")
<< " Acls.func1()" << endl;
return 0;
}
> ] ERROR: Demon not responding. Open pentagram to continue.....
---
---------------
* Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750)
|