不可能从外部隐藏模板的实现(用于保护知识产权).我对吗? [英] It is impossible to hide implementation of templates (for protection of intellectual property) from outside eyes. Am I right?

查看:53
本文介绍了不可能从外部隐藏模板的实现(用于保护知识产权).我对吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读为什么只能将模板在头文件中实现?为什么我不能将模板类的定义与其声明分开,然后将其放入.cpp文件中?

如果我创建模板,那么除了提供它们的 h 文件外,我还将提供对它们的 cpp 文件的访问权限,或者直接将定义写在头文件中

If I create the templates then I am to provide access also to their cpp-files additionally to their h-files, or write the definitions directly in the header file.

因此,如果我想允许我的模板在其他应用程序中完全使用,那么我将无法从外部掩盖它们的实现(用于保护知识产权).我说的对吗?

Therefore, if I want to allow to use fully my templates in other applications, then I can't hide their implementation from outside eyes (for protection of intellectual property). Am I right?

推荐答案

总的来说,您是对的...实现必须公开.

In general you're right... the implementation must be exposed.

如果您的客户只需要实例化它们可以为您列出的一组特定类型的有限类型,则可以为他们提供一个预编译的对象/库,其中仅包含这些类型的实例化的实现:请参见 https://isocpp.org/wiki/faq/templates#从范本中分离模板fn-defn-

If your client only needs to instantiate them for a finite set of specific types that they can list for you, you can provide them with a pre-compiled object/library containing the implementations of the instantiations for just those types: see https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl

混淆是另一种可能性-让他们看到代码,但使代码混乱且难以维护.

Obfuscation is another possibility - let them see the code, but make it confusing and unmaintainable.

如果这些选项都不适合,请考虑是否可以提供模板适配器,以在其用户提供的类型上创建运行时多态接口,从而捕获算法所需的特定功能集.接受这些适配器作为代码的前端.这确实有运行时成本.

If neither of those options suit, consider whether you can provide a templated adapter that creates a run-time polymorphic interface over their user-provided type, capturing the specific set of functions your algorithms need. Accept those adapters as a front-end to your code. This does have runtime costs.

这篇关于不可能从外部隐藏模板的实现(用于保护知识产权).我对吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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