我在同一个.cpp文件中有两个类:
// forward
class B;
class A {
void doSomething(B * b) {
b->add();
}
};
class B {
void add() {
...
}
};
前向传递不起作用,我无法编译。
我收到了这个错误:
error: member access into incomplete type 'B'
note: forward declaration of 'B'
我正在使用clang编译器(clang-500.2.79)。
我不想使用多个文件(.cpp和.hh),我想只在一个.cpp文件上编写代码。
我不能先写类B再写类A。
你有任何解决我的问题的想法吗?
A::doSomething
函数体移动到B
类的定义之后。 - dyp_b
。它们可能会被编译器/标准库在全局命名空间中使用;此外,您绝对不应该使用以下划线开头并后跟大写字母的标识符,例如_B
(也是保留的)。 - dyp