Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
C++20 引入了模块。任何未在模块中导出的符号都具有模块内部链接。虽然未命名的命名空间提供了一种机制,使未命名命名空间内的定义具有文件内部链接。这是否意味着将来当模块在 C++ 社区中变得普遍时,未命名的命名空间将变得无用?
否:因为(许多)编译器一次只能看到一个翻译单元,所以它对于优化来说仍然有用,以表明一个实体不能在任何其他中使用。它还避免了模块单元之间发生意外碰撞的可能性(即使这些碰撞的可能性应该低于更广泛的代码库)。