什么是C ++中的外部链接和内部链接 [英] What is external linkage and internal linkage in C++

查看:230
本文介绍了什么是C ++中的外部链接和内部链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解外部链接和内部链接及其差异。



我也想知道

的意义


extern 。



<当你写一个实现文件( .cpp .cxx 等),您的编译器会生成翻译单元。这是你的实现文件中的目标文件加上你 #include d中的所有头。



内部链接仅指翻译单位范围内的所有内容。



外部链接是指存在于特定翻译单元之外的内容。换句话说,可通过整个程序访问,这是所有翻译单元(或对象文件)的组合。


I want to understand the external linkage and internal linkage and their difference.

I also want to know the meaning of

const variables internally link by default unless otherwise declared as extern.

解决方案

When you write an implementation file (.cpp, .cxx, etc) your compiler generates a translation unit. This is the object file from your implementation file plus all the headers you #included in it.

Internal linkage refers to everything only in scope of a translation unit.

External linkage refers to things that exist beyond a particular translation unit. In other words, accessible through the whole program, which is the combination of all translation units (or object files).

这篇关于什么是C ++中的外部链接和内部链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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