错误:成员访问不完全类型:正向声明 [英] error: member access into incomplete type : forward declaration of
本文介绍了错误:成员访问不完全类型:正向声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在同一个.cpp上有两个类:
I have two class on the same .cpp like that :
//forward
class B;
class A {
void doSomething(B * _b) {
_b->add();
}
};
class B {
void add() {
...
}
};
前进不起作用,我无法编译。
The forward does not work, I cannot compile.
我有这个错误:
error: member access into incomplete type 'B'
note: forward declaration of 'B'
我使用clang编译器(clang-500.2.79)。
I'm using clang compiler (clang-500.2.79).
我不想使用多个文件(.cpp和.hh),我想在一个.cpp上编码。
我无法在A类之前写B类。
有任何想法,以解决我的问题?
Do you have any idea to resolving my problem ?
最好的问候。
推荐答案
移动 doSomething
c $ c> B 并且可以访问
-ing it或 A
c> public friend
。
Move doSomething
definition outside of its class declaration and after B
and also make add
accessible to A
by public
-ing it or friend
-ing it.
class B;
class A
{
void doSomething(B * b);
};
class B
{
public:
void add() {}
};
void A::doSomething(B * b)
{
b->add();
}
这篇关于错误:成员访问不完全类型:正向声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文