我有两个类:A和B.类A的一些方法需要使用类B而相反(类B有需要使用类A的方法).
所以我有:
class A;
class B {
method1(A a) {
}
}
class A {
method1(B b) {
}
void foo() {
}
}
Run Code Online (Sandbox Code Playgroud)
一切正常.
但是当我尝试从B :: method1调用类A的foo()时:
class B {
method1(A a) {
a.foo();
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的结果是前向声明的编译错误和 不完整类型的使用.但为什么会这样呢?(我在使用之前已经宣布了A级?)