相关疑难解决方法(0)

错误:成员访问不完整类型:转发声明

我在同一个.cpp上有两个类:

// forward
class B;

class A {       
   void doSomething(B * b) {
      b->add();
   }
};

class B {
   void add() {
      ...
   }
};
Run Code Online (Sandbox Code Playgroud)

前进不起作用,我无法编译.

我有这个错误:

error: member access into incomplete type 'B'
note: forward declaration of 'B'
Run Code Online (Sandbox Code Playgroud)

我正在使用clang编译器(clang-500.2.79).

我不想使用多个文件(.cpp和.hh),我想在一个.cpp上编码.

我不能在A班之前写B班.

你有什么想法解决我的问题吗?

最好的祝福.

c++ forward-declaration

37
推荐指数
2
解决办法
8万
查看次数

标签 统计

c++ ×1

forward-declaration ×1