具有成员函数的两个类从另一个类获取指向对象的指针
Two classes with member functions taking a pointer to an object from the other class
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);
};
相关文章:
- 如何通过按下第三个窗口中的按钮,将QString从一个窗口获取到另一个窗口
- 如何巧妙地编写两个函数——一个用于检查是否存在解决方案,另一个用于获取所有解决方案
- 重载运算符*以获取对另一个类的实例的引用
- 互斥,Windows 10,c ++,在一个线程上获取,在另一个线程上发布
- 如何从一个容器中获取某些元素并将其转换插入到另一个容器中?
- 是否有可能通过指向另一个未关联的子对象的指针来获取指向一个子对象的指针?
- openmp 锁由同一线程重新获取,而另一个线程正在等待它
- 为什么相同的函数签名只有区别,另一个通过 const 获取参数是重新定义?
- 使用 c++ / QT 创建器从另一个类中设置和获取单例变量
- 如何在另一个线程中关闭 MFC 模式对话框并获取对话框返回值?
- 一个函数中的变量从另一个函数中的变量中获取值
- C/C++ 从 STM32 中的另一个类获取大型数据,如 180 数组
- 如何从另一个类动态获取整数?
- 是否可以注入一个进程并获取给定的句柄,然后使用它们注入另一个进程
- 您什么时候使用哪种方法从另一个文件中获取变量
- 呼叫获取后,将共享_ptr分配给另一个
- 尝试从另一个类对象获取值时出现分段错误
- 从一个案例获取信息到另一个案例
- 有没有办法获取容器模板类型以将其与另一个value_type重用
- 如何在指定数据之间将数据从一个向量获取到另一个向量