首页> 外文期刊>MSDN Magazine >PURE C++: Generic Programming: Template Specialization
【24h】

PURE C++: Generic Programming: Template Specialization

机译:PURE C ++:通用编程:模板专业化

获取原文
获取原文并翻译 | 示例

摘要

As I discussed in my last column, a parameterized type that does more than simple storage and retrieval is constrained as to the acceptable types that may be safely bound to it (see msdn.microsoft.com/msdnmag/issues/05/06/PureC). Using generics, these constraints are made explicit through the where clause. In the C++/CLI template facility, you can often work around these constraints by specializing a function or class template—either individual member functions or an entire class. For the sake of illustration, let's add a min function to my tStack class from the previous column. Ordinarily, I would use the generic min algorithm, but that would only help me as a programmer, not as author of an article on template specialization. For your convenience, the tStack class template definition is reproduced in Figure 1.
机译:正如我在上一专栏文章中讨论的那样,除了可以简单地进行存储和检索外,参数化类型还可以安全地绑定到可接受的类型(请参阅msdn.microsoft.com/msdnmag/issues/05/06/PureC )。使用泛型,这些约束通过where子句明确显示。在C ++ / CLI模板工具中,您通常可以通过专门化函数或类模板(单个成员函数或整个类)来解决这些约束。为了说明起见,让我们从上一专栏向我的tStack类添加一个min函数。通常,我会使用通用的min算法,但这只会帮助我成为一名程序员,而不是作为模板专业化文章的作者。为了您的方便,图1中复制了tStack类模板定义。

著录项

相似文献

  • 外文文献
  • 中文文献
  • 专利
获取原文

客服邮箱:kefu@zhangqiaokeyan.com

京公网安备:11010802029741号 ICP备案号:京ICP备15016152号-6 六维联合信息科技 (北京) 有限公司©版权所有
  • 客服微信

  • 服务号