在名称空间中包装外部库 [英] Wrapping external libraries in namespaces

查看:56
本文介绍了在名称空间中包装外部库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个可在我的项目中使用的库.在其中,我希望将c标准库包装在我的库的命名空间和cstd命名空间中,以避免将其功能包含在全局命名空间中.但是,从我之前提出的问题以及经过测试的结果来看,我不能仅仅将所有内容都包含在命名空间中.有什么办法吗?

I'm writing a library to use in my projects. In it, I was hoping to wrap the c standard library in my library's namespace and a cstd namespace to avoid having its functions in the global namespace. However, from a previous question I asked and from what I've tested, I can't just #include everything in a namespace. Is there any way to do this?

推荐答案

除非您想重写所有内容,否则我对此表示怀疑.

I doubt it, unless you wanted to rewrite everything.

C语言本身没有名称空间的概念,因此C标准库使用的所有内容都必须依赖于以下事实:要查找的内容都位于全局名称空间中.

The C language itself has no concept of namespaces, so everything the C standard library uses must rely on the fact that whatever it is looking for resides in the global namespace.

如果只是在#include周围包裹一个名称空间,则编译器将无法找到任何内容,因为它不知道要查找的名称空间.

If you simply wrapped a namespace around your #includes, the compiler wouldn't be able to find anything because it wouldn't know what namespace to look in.

这篇关于在名称空间中包装外部库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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