多个cpp文件的一个标题 [英] One header for multiple cpp-files

查看:94
本文介绍了多个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.

这篇关于多个cpp文件的一个标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆