我得到错误<<'A :: b'使用未定义的类'B'>>在c ++中 [英] I get Error <<'A::b' uses undefined class 'B'>> in c++
本文介绍了我得到错误<<'A :: b'使用未定义的类'B'>>在c ++中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码
I have below Code
class B;
class A
{
B b;
};
class B
{
A a;
};
但我收到错误<<'A :: b'使用未定义的类'B'>>
如何使用模板解决它
But I get Error <<'A::b' uses undefined class 'B'>>
How I can to use template for solve it
推荐答案
如果可能,你无法初始化任何实例这些类,因为它会递归地创建无限数量的A
和B
实例。但是你可以将这些类型的指针作为实例成员。你应该避免使用无限递归实例化的情况,即使使用指针也是如此。例如,如果a
和b
是指针,aB
并且bA
可以指向对方。
-SA
If it was possible, you could not initialize the instances of any of these classes, because it would recursively create infinite number ofA
andB
instances. But you could have a pointers of these types as instance members. You should avoid the situation with infinite recursive instantiation, even with pointers. For example, ifa
andb
were pointers,a.B
andb.A
could point to each other.
—SA
这篇关于我得到错误<<'A :: b'使用未定义的类'B'>>在c ++中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文