c++ - 接口(interface)集合相互依赖

标签 c++ interface

让我有两个接口(interface):

class foo{
public:
    virtual void fooo(bar * b)=0;
}

class bar{
public:
    virtual void barr(foo * f)=0;
}

但是这段代码格式不正确。如何正确编写此接口(interface)?

最佳答案

How can I write this interfaces correctly?

您始终可以转发声明类,并在看到转发声明的代码中使用指针或引用。
一旦任何代码需要引用类成员,就必须看到完整的类声明。

class bar; // << Note the forward declaration
class foo{
public:
    virtual void fooo(bar * b)=0;
}

class bar{
public:
    virtual void barr(foo * f)=0;
}

关于c++ - 接口(interface)集合相互依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23442038/

相关文章:

c++ - 如何以程序员愉快的方式使用 CUDA 常量内存?

c++ - 获取UDP数据包的目的地址

c++ - 在没有嵌套 for 循环的情况下查找另一个 vector 中 vector 条目的出现

c++ - 在 C++ 中编译和链接多个文件

c# - 如何在 C# 中正确设计通用接口(interface)及其非通用接口(interface)?

c# - 如何在 C# 接口(interface)中使用泛型类型参数

空体的 C++ 函数与没有体的函数

c# - 实现接口(interface)的好处

c++ - C++ 中的 Const 函数和接口(interface)

c# - 还有哪些其他语言支持 Go 的接口(interface)风格而无需显式声明?