关于模版的一个问题
来源:互联网 发布:js设置div title属性 编辑:程序博客网 时间:2024/05/16 07:09
http://www.cplusplus.com/doc/tutorial/templates/
Templates and multiple-file projects
From the point of view of the compiler, templates are not normal functions or classes. They are compiled on demand, meaning that the code of a template function is not compiled until an instantiation with specific template arguments is required. At that moment, when an instantiation is required, the compiler generates a function specifically for those arguments from the template.
When projects grow it is usual to split the code of a program in different source code files. In these cases, the interface and implementation are generally separated. Taking a library of functions as example, the interface generally consists of declarations of the prototypes of all the functions that can be called. These are generally declared in a "header file" with a .h extension, and the implementation (the definition of these functions) is in an independent file with c++ code.
Because templates are compiled when required, this forces a restriction for multi-file projects: the implementation (definition) of a template class or function must be in the same file as its declaration. That means that we cannot separate the interface in a separate header file, and that we must include both interface and implementation in any file that uses the templates.
Since no code is generated until a template is instantiated when required, compilers are prepared to allow the inclusion more than once of the same template file with both declarations and definitions in a project without generating linkage errors.
- 关于模版的一个问题
- 关于模版一个问题的测试
- 关于C++模版的连接错误问题
- 关于bootstrap模版Bootstrapper的问题
- mapreduce的一个模版
- 关于“树”的模版
- 关于C++模版的代码文件放置问题
- 关于模版类或者函数的使用问题
- 关于模版类编译出现unresolved external symbol的问题
- Tp5关于include模版标签的使用和模版缓存问题
- 一个简单的模版控件
- 一个常用的makefile模版
- 一个简单的makefile模版
- 一个简单的函数模版
- 一个奇特的模版函数
- 关于C++的函数模版
- 关于java的注释模版
- 关于模版的实参推演
- java操作文本文件
- php MYSQL数据库连接和乱码现像
- 动态规划 和 背包问题的一个讲座
- 迅雷快速下载 Android SDK相关
- 工作心得
- 关于模版的一个问题
- 查看链接哪些库的编译选项
- [转]VC 2008 远程调试
- 组合与聚合的选用 (Composition & Aggregation)
- 心情
- PHP 向其它PHP页面传参的两次方式,包括传参不刷新,不使用POST GET
- andoird wifi 点对点连接笔记本的ad-hoc
- 7月1日
- 领域驱动设计和开发实战