类原型 [英] Class prototyping
问题描述
我在类a中放置了类b的几个实例,但这会导致错误,因为类a不知道类b是什么。
I have put several instances of class b in class a but this causes an error as class a does not know what class b is.
现在,我知道我可以通过将文件b a c写入文件来解决此问题,但是这不仅影响了可访问性,而且使我感到烦恼。我知道我可以原型化我的函数,所以我没有这个问题,但是找不到关于如何原型化类的材料。
Now I know I can solve this problem by writing my file b a c but this messes up the reachability as well as annoys me. I know I can prototype my functions so I do not have this problem but have been able to find no material on how to prototype a class.
没有人有c ++中的类原型示例。
does anyone have an example of class prototyping in c++.
因为似乎有些混乱,让我向您展示我想要的东西
as there seems to be some confusion let me show you what i want
class A
{
public:
B foo[5];
};
class B
{
public:
int foo;
char bar;
}
但这不起作用,因为A无法看到B,所以我需要放点东西在他们两个人之前,如果这是一个函数,我会把A();然后实施。
but this does not work as A cannot see B so i need to put something before them both, if it was a function i would put A(); then implement it later. how can i do this with a class.
推荐答案
您可以声明所有类,然后以任何顺序定义它们,就像这样:
You can declare all your classes and then define them in any order, like so:
// Declare my classes
class A;
class B;
class C;
// Define my classes (any order will do)
class A { ... };
class B { ... };
class C { ... };
这篇关于类原型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!