【发布时间】:2021-08-11 02:22:07
【问题描述】:
如果我在类中有这样的嵌套结构:
(a.h file)
class A{
public:
struct B{...};
};
我想在其他 .h 文件中传递引用 A::B 的参数。我该怎么做? 我想做:
(b.h file)
class B{
randomMethod(A::B arg0);
};
我听说在 .h 文件中包含其他 .h 文件不是一个好习惯。所以我尝试在B类之前添加一些类声明,但它不起作用。 我试过了:
class A::B;
class B{...}
or
class A;
class A::B;
class B{...}
【问题讨论】:
-
“我听说在 .h 文件中包含其他 .h 文件不是一个好习惯。”什么?你从哪里听到的?
标签: c++ class reference header-files