显式实例化 - 何时使用? [英] Explicit instantiation - when is it used?

查看:124
本文介绍了显式实例化 - 何时使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个星期后,我试图扩展和扩展我的模板的知识与书模板–完整指南由David Vandevoorde和Nicolai M. Josuttis发表,我目前想要了解的是模板的显式实例化。

After few weeks break, I'm trying to expand and extend my knowlege of templates with the book Templates – The Complete Guide by David Vandevoorde and Nicolai M. Josuttis, and what I'm trying to understand at this moment is explicit instantiation of templates.

实际上有这样的机制的问题,但我不能想象一种情况,我想或想要使用此功能。

I don't actually have a problem with the mechanism as such, but I can't imagine a situation in which I would like or want to use this feature. If anyone can explain that to me I will be more than grateful.

推荐答案

直接从 http://msdn.microsoft.com/en-us/library/by56e477%28VS.80%29.aspx


显式实例化可以创建模板类或函数的实例化,而不必在代码中实际使用。因为当您创建使用模板的库(.lib)进行分发时,这是非常有用的,未定义的模板定义不会放入对象(.obj)文件中。

Explicit instantiation lets you create an instantiation of a templated class or function without actually using it in your code. Because this is useful when you are creating library (.lib) files that use templates for distribution, uninstantiated template definitions are not put into object (.obj) files.

(例如,libstdc ++包含 std :: basic_string< char,char_traits< char>,allocator< char>因此每次使用 std :: string 的函数时,code>( std :: string ,相同的函数代码不需要复制到对象,编译器只需要引用(链接)到libstdc ++。)

(For instance, libstdc++ contains the explicit instantiation of std::basic_string<char,char_traits<char>,allocator<char> > (which is std::string) so every time you use functions of std::string, the same function code doesn't need to be copied to objects. The compiler only need to refer (link) those to libstdc++.)

这篇关于显式实例化 - 何时使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆