`

c++ - template function the compilation model correctum

    博客分类:
  • c++
c++ 
阅读更多

In the book - the C++ Primer 3rd edition, Stanley Lippman has introduced something about the compilatio model . He introduced two models. 

 

  • inclusion compilation model 
  • separation compilation model 

 

 

with inclusion compilation model, the definition of the function template is included in the header file, while every source file that instantiates the function template is required to include the header file.

 

for space 's reason, I will not introduce the inclusion model in details. 

 

He also introduced the separation model . 

 

the quintessence/gist/marrow/essence/heart of the separation model is in the header file there is only the function template's declaration, and definition of the function template can goes into a separate source file.  Client to the template function can include the header file and the the separate source file will have an export keyword to qualify the function's definition. 

 

it is suppose to be like this; 

 

// model2.h

 

template <typename Type> Type min2(Type t1, Type t2);

 // model2.C

 

export template <typename Type>
	Type min2(Type t1, Type t2) { 
    return t1 < t2 ? t1 : t2;
}

 and if you wan to use the template function , say in user.C , do this 

 

 

#include "model2.h"

int main2(int argc, char* argv[]) 
{
	int i, j; 

	double dobj  = min2(i, j);
	return 0;
}

 

!!!BUT!!!!

 

However, the prolem is that the compiler that I tried, inlcuding the vc++ 11 or the gnu c++ does not support the export keyword, so I think it is not supported to have separation compilation model .

分享到:
评论

相关推荐

    Analog-Circuit-compilation-yang(新概念模拟电路).zip

    《新概念模拟电路》系列书籍是由著名放大器领域的专家所著,旨在深入浅出地讲解模拟电路的基础理论和实际应用。资源出自全球知名的半导体公司ADI(Analog Devices Inc.),这意味着书中涵盖的内容不仅有深厚的理论...

    QGIScode QGIS-Code-Examples QGIS-Compilation-Guide QGIS-Document

    2. **QGIS-Compilation-Guide**: 编译指南详细介绍了如何从源代码编译QGIS,这对于开发者来说是必不可少的。这里可能包含构建环境的设置、依赖库的安装、编译选项的选择等。通过这个指南,你可以了解软件工程中的...

    Turbo C++ 3.0[DISK]

    Computer brand, model, and the brands and model numbers of any additional hardware. d. Operating system and version number. (The version number can be determined by typing VER at the DOS prompt.)...

    Analog-Circuit-compilation-yang.zip

    《新概念模拟电路》系列是ADI公司发布的一套专业教程,涵盖了广泛的模拟电路知识,旨在为电路设计者和学习者提供深入的理解与实践指导。这一系列共有五册,分别是《Analog Circuit I》、《Analog Circuit II》、...

    Turbo C++ 3.00[DISK]

    Computer brand, model, and the brands and model numbers of any additional hardware. d. Operating system and version number. (The version number can be determined by typing VER at the DOS prompt.)...

    Learning Boost C++ Libraries.pdf

    compilation model, and be able to use a C++ development environment on Linux, Windows, or Mac OS. This book does not cover general C++ concepts as a rule, but some useful C++ books and articles, ...

    DE2官方文件-DE2_synthesizer

    The compiled_partitions sub-folder contains previous compilation results for each partition. As long as this folder is preserved, incremental compilation results from earlier compiles can be re-used. ...

    linux软件编译,安装。_Linux-Software-compilation.zip

    linux软件编译,安装。_Linux-Software-compilation

    Google C++ Style Guide_英文版.pdf

    - **Function Comments:** Describe what the function does, its parameters, and any side effects. - **Variable Comments:** Explain the purpose of important variables. - **Implementation Comments:** ...

    Practical C++ Programming C++编程实践

    The C++ Preprocessor define Statement Conditional Compilation include Files Parameterized Macros Advanced Features Summary Programming Exercises Answers to Chapter Questions 11. Bit Operations Bit ...

    Art-Exploring-the-New-Android-KitKat-Runtime

    标题《Art-Exploring-the-New-Android-KitKat-Runtime》中的知识点涵盖了Android KitKat操作系统版本中引入的新运行时环境(Runtime Environment),特别是ART(Android Runtime)的探索和分析。Android KitKat是...

    Bloodshed Dev-C++

    * Added the possibility to specify an include directory for the code completion cache to be created at Dev-C++ first startup * Improved code completion cache * WebUpdate will now backup downloaded ...

    univ-lr__Compilation__TEA

    标题“univ-lr__Compilation__TEA”和描述“univ-lr__编译__TEA”都指向了一个关于大学(univ-lr)的编程项目,其中涉及了编译(Compilation)和TEA(可能是指Tiny Encryption Algorithm,一种简单的加密算法)。...

    maven-incremental-compilation

    [INFO] --- takari-lifecycle-plugin:1.10.2:compile (default-compile) @ maven-incremental-compilation --- [INFO] Performing incremental build [INFO] Compiling 2 sources to /home/mariuszs/git/maven-...

    acpi控制笔记本风扇转速

    Fixed a compilation problem with the pre-defined Resource Descriptor field names where an "object does not exist" error could be incorrectly generated if the parent ResourceTemplate pathname places ...

    issrc-5.3.3.zip_The Front_delphi inno setup

    do the actual compilation itself it relegates it to ISCmplr.dll. If the ISCmplr project is changed, you normally don t need to recompile Compil32 since it s essentially a text editor, and is not ...

    gentoo-sources-compilation-helper:如果您厌倦了手动(重新)为N编译您的gentoo源-Lazy source

    gch - gentoo-sources compilation helper 版本 0.20 概要: gch.sh [--help|-h] [--version|-v] [--kernel|-k ] [--initramfs|-i] [--yestoall|-y] 描述 If you're tired of manually (re)compiling your gentoo-...

    Modern C++ Programming Cookbook

    Work with various types of strings and look at the various aspects of compilation Explore functions and callable objects with a focus on modern features Leverage the standard library and work with ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    Also added the parameter LengthPos in the function PointOnLine (see the updated tutorial-project CurveDemo). These functions allow defining a point on a curve by the distance from the original ...

Global site tag (gtag.js) - Google Analytics