[英]How can I define two inter dependant classes, preferably in the same header file?
So, I want something like: 所以,我想要的东西:
class A{
B member;
};
class B{
A function();
};
No matter in which order I declare them, I get an incomplete type error (and I pretty much understand why). 无论我以什么顺序声明它们,我都会得到一个不完整的类型错误(我非常理解为什么)。 How can I solve this? 我怎么解决这个问题? I don't want to use pointers or to have the function defined outside the B class. 我不想使用指针或在B类之外定义函数。 Also, declaring them before as 另外,在之前声明它们
class A; class B;
doesn't seem to work either. 似乎也没有用。
No need for class definition when declare a function. 声明函数时不需要类定义。
class A;
class B{
A function();
};
class A{
B member;
};
This order will work: 此订单将起作用:
class A;
class B {
A function();
};
class A {
B member;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.