头文件和命名空间有什么区别? [英] What is the difference between header file and namespace?
问题描述
我想知道在编程语言中考虑的头文件和命名空间之间的确切区别
I want to know the exact difference between Header file and namespace in consideration in programming languages ??
推荐答案
头文件实际文件 - 存储在文件系统中,由文件名引用,并且 #include
在其他文件中(至少使用C / C ++或其他语言使用M4宏预处理器)。标题文件通常将作为相同特定项目的所有相互依赖部分的代码片段组合在一起。例如,一个游戏可能有一个头文件用于所有的图形渲染。
Header files are actual files - stored in the file system, referenced by file name, and #include
'd in other files (at least, in C/C++ or other languages using the M4 macro preprocessor). Header files typically group pieces of code that are all interdependent parts of the same specific item together. For instance, a game might have a header file for all of its graphics rendering.
另一方面,Namespaces是编程语言的一个元素 - t作为文件系统对象存在,而是作为代码中的指定,告诉编译器某些事物在该命名空间内。命名空间通常对类似(但不一定是相互依赖)项目的接口(函数,类/结构,类型)进行分组。例如,C ++中的 std
命名空间包含所有标准库函数和类。
Namespaces, on the other hand, are an element of the programming language - they don't exist as a file system object, but rather as a designation within code telling the compiler that certain things are within that namespace. Namespaces typically group interfaces (functions, classes/structs, types) of similar (but not necessarily interdependent) items. For instance, the std
namespace in C++ contains all of the Standard Library functions and classes.
这篇关于头文件和命名空间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!