c++ - template function the compilation model correctum_C/C++_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > C/C++ > c++ - template function the compilation model correctum

c++ - template function the compilation model correctum

 2012/9/8 11:51:02  joe.bq.wang  程序员俱乐部  我要评论(0)
  • 摘要:Inthebook-theC++Primer3rdedition,StanleyLippmanhasintroducedsomethingaboutthecompilatiomodel.Heintroducedtwomodels.inclusioncompilationmodelseparationcompilationmodelwithinclusioncompilationmodel
  • 标签:c++ function

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 .

发表评论
用户名: 匿名