-1
class A;
class B;
class A
{
public:
A(B * b) : b(b)
{
b->foo(this);
}
private:
B * b;
};
class B
{
public:
void foo(A *)
{}
};
编译此代码,使班给我如何利用彼此
incomplete-type.hpp: In constructor ‘A::A(B*)’:
incomplete-type.hpp:9:4: error: invalid use of incomplete type ‘class B’
b->foo(this);
^~
但我真的需要的类通过指针相互使用对方。我怎样才能做到这一点?
定义类定义之外的构造函数,并定义了两个类之后。 – wally