我是否应该为 a) 所有前向声明和 b) public 函数设置两个 headers

Should I have two headers for both a) all the forward declarations AND b) the public functions

假设我有 file_a.cpp 文件,其中 function_a() 将用于 file_b.cpp,而 function_b() 仅用于 [=] 16=]。所以我想到的是在声明 function_a() 的地方制作 file_a_public.h,这样我就可以将其包含在 file_b.cpp 中。然后在 file_a_private.h 中转发声明 file_a.cpp 的所有函数,因此我可以将其包含在 file_a.cpp 中。我知道如果我只是以正确的顺序定义函数,我就不需要 file_a_private.h,但这可能很困难或不可能。

有两个 header 文件我应该怎么做,还是我在这里遗漏了什么?

你说你不需要 file_a_private.h 如果你能以正确的顺序定义函数。但是随后您可以在 file_a.cpp 中以正确的顺序 声明 这些函数(可能在未命名的命名空间内),然后再定义这些函数。那么不需要包含 file_a_private.h