标题库的优点 [英] Benefits of header-only libraries

查看:178
本文介绍了标题库的优点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标头唯一库的好处是什么,为什么要这样写呢?

What are the benefits of a header only library and why would you write it that way oppose to putting the implementation into separate file?

推荐答案

有些情况下只有标题库是唯一的选项,例如在处理模板时。

There are situations when a header-only library is the only option, for example when dealing with templates.

只有标题库也意味着你不必担心可能使用库的不同平台。当你分离实现时,通常这样做是为了隐藏实现细节,并将库作为头和库的组合来分发( lib dll '或 .so 文件)。这些当然必须为您提供支持的所有不同的操作系统/版本编译。

Having a header-only library also means you don't have to worry about different platforms where the library might be used. When you separate the implementation, you usually do so to hide implementation details, and distribute the library as a combination of headers and libraries (lib, dll's or .so files). These of course have to be compiled for all different operating systems/versions you offer support.

您还可以分发实现文件,但这将意味着一个额外的步骤

You could also distribute the implementation files, but that would mean an extra step for the user - compiling your library before using it.

当然,这种情况适用于 case-by-case 。例如,头文件库有时会增加代码大小& 编译时间。

Of course, this applies on a case-by-case basis. For example, header-only libraries sometimes increase code size & compilation times.

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

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