简体   繁体   English

在仅标头库中隐藏实现

[英]Hide implementation in header-only library

I've tried to use an implementation namespace, but when i 'using namespace' it, it pulls in the whole implementation namespace, rendering it useless. 我尝试使用实现名称空间,但是当我“使用名称空间”时,它会拉入整个实现名称空间,使其变得无用。

namespace library {
 namespace implementation {
  //implementation
 }

 using namespace implementation

 //visible identifiers
}

Is there way to hide implementation, without needing to use "implementation::" before using anything from implementation? 有什么方法可以隐藏实现,而无需在实现中使用任何东西之前使用“ implementation ::”?

rendering it useless 使其变得无用

Well, it's not useless, you just can't using namespace it. 好吧,这不是没有用的,只是不能using namespace You have to explicitly prepend implementation:: to the names in it. 您必须在其中的名称之前显式地implementation:: For this reason, it might make sense to choose a shorter name ( detail is commonly used in c++ projects for this purpose). 因此,选择一个较短的名称可能很有意义(为此,在c ++项目中通常使用detail )。

Also, I'd like to point out that header-only and implementation hiding are two somewhat conflicting requirements. 另外,我想指出,仅标头和实现隐藏是两个相互冲突的要求。 If you truly need to hide the implementation, you can't go header-only. 如果您确实需要隐藏实现,则不能只使用标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM