如何将C++模板编写的库闭源

发布于 2024-10-20 15:44:32 字数 202 浏览 1 评论 0原文

阅读这篇文章在.CPP文件中存储C++模板函数定义后,我知道使用模板的类的定义必须以某种方式写入头文件中。因此客户端用户可以通过导入头文件来使用它。这不是意味着完整的实现细节已经向用户公开了吗?这是否也意味着用模板编写的库必须以开源方式提供?

感谢您帮助澄清。

After reading this article Storing C++ template function definitions in a .CPP file, I know that the definition of a class that uses template has to be written in the header file in some way. So a client user can use it by importing the header files. Doesn't this mean the complete implementation details are revealed to the user? Does this also mean a library written with template must be provided in an open-source way?

Thanks for helping clarify it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月无声 2024-10-27 15:44:32
  1. 模板实现的详细信息将可见。但是,如果您知道哪些参数是必需的,则可以提供显式模板实例化。但要成为通用解决方案,您必须提供实现,以便它可以与其他参数一起使用。

  2. 不,您不必将其作为开源版本发布。仅仅因为有人可以看到代码,并不意味着它必须是开源的。您几乎可以随心所欲地许可它,并且购买者必须遵守这些规则。毕竟,仅仅因为我们可以看到小说的整个文本并不意味着我们可以用它做任何我们想做的事情。

  1. The details of the template implementation will be visible. You can provide explicit template instantiations if you know which parameters will be necessary, however. But to be a generic solution, you have to provide the implementation so it can be used with other parameters.

  2. No, you don't have to release it as open source. Just because someone can see the code, doesn't mean it has to be open source. You can license it almost however you want, and the purchaser has to abide by those rules. After all, just because we can see the entire text of a novel doesn't mean we can do whatever we want with it.

你げ笑在眉眼 2024-10-27 15:44:32

是的,基于模板的 C++ 库公开了它们的实现。提供源代码与“开源”不同。 Microsoft 提供了 MFC 的源代码,但它不是开源的。许可证发挥着重要作用。

Yes, template-based C++ libraries expose their implementations. Providing source is not the same thing as "open source." Microsoft supplies the source to MFC, but it isn't open source. The license makes the difference.

吃不饱 2024-10-27 15:44:32

是的,这确实意味着基于模板的库通常有源代码。这与通常使用“开源”的方式并不特别相似。话又说回来,大多数好的库在任何情况下都提供源代码。

It does mean that template-based libraries normally have supply source code, yes. That isn't particularly similar to how "open source" is typically used. Then again, most good libraries supply source code in any case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文