在 header-only 库中隐藏实现
Hide implementation in header-only library
我曾尝试使用实现命名空间,但是当我 'using namespace' 它时,它会拉入整个实现命名空间,使其变得无用。
namespace library {
namespace implementation {
//implementation
}
using namespace implementation
//visible identifiers
}
有没有办法隐藏实现,而不需要在使用任何实现之前使用 "implementation::"?
rendering it useless
嗯,它不是没用,只是你不能 using namespace
它。您必须明确地将 implementation::
添加到其中的名称。出于这个原因,选择一个较短的名称可能是有意义的(detail
通常在 c++ 项目中用于此目的)。
此外,我想指出 header-only 和实现隐藏是两个有些矛盾的要求。如果你真的需要隐藏实现,你不能去 header-only.
我曾尝试使用实现命名空间,但是当我 'using namespace' 它时,它会拉入整个实现命名空间,使其变得无用。
namespace library {
namespace implementation {
//implementation
}
using namespace implementation
//visible identifiers
}
有没有办法隐藏实现,而不需要在使用任何实现之前使用 "implementation::"?
rendering it useless
嗯,它不是没用,只是你不能 using namespace
它。您必须明确地将 implementation::
添加到其中的名称。出于这个原因,选择一个较短的名称可能是有意义的(detail
通常在 c++ 项目中用于此目的)。
此外,我想指出 header-only 和实现隐藏是两个有些矛盾的要求。如果你真的需要隐藏实现,你不能去 header-only.