且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么const暗示内部链接在C ++中,当它不在C?

更新时间:2023-11-13 23:20:52

I believe you mean

Why does const imply internal linkage in C++

It's true that if you declare a const object at namespace scope, then it has internal linkage.

Appendix C gives the rationale

Change: A name of file scope that is explicitly declared const, and not explicitly declared extern, has internal linkage, while in C it would have external linkage

Rationale: Because const objects can be used as compile-time values in C++, this feature urges programmers to provide explicit initializer values for each const. This feature allows the user to put const objects in header files that are included in many compilation units.

相关阅读

推荐文章