class a {
public:
void f2(b * elem);
};
class b {
public:
void f1(a * elem);
};
这里会有问题
void f2(b * elem);
如何以可以使用函数 f2
的方式声明类 b
?
最佳答案
告诉编译器有一个类a和b。但是不要告诉他/她他们长什么样 :) 这是可能的,因为你使用的是指针。它只是编译器的整数。稍后您可以定义类的所有功能,编译器现在很乐意知道它们的外观。
class a; // tell the compiler there is a class a
class b; // tell the compiler there is a class b
// real implementation of class a
class a {
public:
void f2(b * elem);
};
// real implementation of class b
class b {
public:
void f1(a * elem);
};
关于c++ - 两个具有成员函数的类从另一个类获取指向对象的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38717088/