C++Primer 第16章-模板与泛型编程-部分选做习题答案 .pdfVIP

  • 3
  • 0
  • 约1.04万字
  • 约 9页
  • 2023-12-04 发布于山东
  • 举报

C++Primer 第16章-模板与泛型编程-部分选做习题答案 .pdf

16 章 部分选做习题 16.1 编写一个模板返回形参的绝对值,至少用三种不同类型的值调用模板。注意:在 16.3 节讨论编译器怎样处理模板实例化之前,你应该将每个模板定义和该模板的所有使用放在同 一文件中。 // 16.1_template.cpp : 定义控制台应用程序的入口点。 // #include stdafx.h #include iostream template typename T inline T abs( T tVal) { return tVal 0 ? tVal : -1*tVal; } int _tmain(int argc, _TCHAR* argv[]) { std::cout \n\tabs( false ) is:\t abs(false) std::endl \n\tabs( -3 ) is:\t\t abs( -3 ) std::endl \n\tabs( -8.6 ) is:\t\t abs( -8.6 ) std::endl; system(pause);

文档评论(0)

1亿VIP精品文档

相关文档