控制实例化
1. 当模板被使用时才会进行实例化,这一特性意味着,相同的实例可能会出现在多个动态文件中。
2. 当两个或多个独立编译的源文件使用了相同的模板,并提供了相同的模板参数时,每个文件中就都会有该模板的一个实例。
3. 在大型系统中,在多个文件中实例化相同模板的的额外开销可能非常严重。
显示实例化:
template int compare(const int&, const int&);
template class Blob<string>; //实例化类模板的所有成员
显示声明:
extern template class Blob<string>;
extern template int compare(const int&, const int&);

浙公网安备 33010602011771号