c++ - template function the compilation model correctum

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 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值