多个cpp文件的一个标题
让我们假设我有3个cpp文件:
Let's assume I have 3 cpp-files:
Main.cpp
First.cpp
Second.cpp
现在我想使用Main中的第一和第二个函数。有没有什么可以抱怨的,如果我只使用一个头文件为两个cpp文件和他们的功能?
Now i want to use functions from First and Second in Main. Is there something to complain about, if I used only one header-file for both cpp-files and their functions?
可能有任何问题,当使用header-文件在第一个,因为我需要一个函数从第二个
Could there be any problems, when using the header-file in First, because I need a Function from Second in First?
只要遵循 ODR - 一个定义规则,每个声明都是一致的,你会很好。
As long as you follow the ODR - One Definition Rule and every declaration is consistent, you will be fine.
标题通常意味着为函数和其他东西提供声明,链接阶段(除非有更多的内容像模板一样)将负责解决这些依赖。
Headers are usually meant to provide declarations for functions and other stuff, the linking phase (except when there's something a bit more involved like templates) will take care of resolving those dependencies.
我不是在设计上说什么 - 没有足够的信息。
I'm not saying anything on the design - not enough info provided.