随笔分类 - c++ templates
模板入门
摘要:#include #include "SeqList.h"using namespace std;int main(){ SeqList test(15); int array[15]={2,5,8,1,9,9,7,6,4,3,2,9,7,7,9}; for(int i=0;iusing names...
阅读全文
摘要:typedef struct Point{ double x,y; bool operator<(const Point &other) const { return x<other.x; }};
阅读全文
摘要:5高阶基本技术(Tricky Basics)本章涵盖实际编程之中层次较高的一些 template基本知识,包括关键词 typename的另一种用途、将member functio(n 成员函数)和 nested clas(s 嵌套类别)定为templates、奇特的 template templat...
阅读全文
摘要:Nontype Template Parameters非类型模板参数对 function templates 和 class templates 而言,template parameters 并不一定非要是类型(types) 不可,它们也可以是常规的(一般的)数值。当你以类型(types)作为 te...
阅读全文
摘要:3.3 Class Templates 的特化( Specializations)你可以针对某些特殊的 template arguments,对一个 class template 进行「特化」。class templates的特化与 function template 的重载类似,使你得以针对某些特...
阅读全文
摘要:Class Templates类别模板就像上一章所说的 functions 那样,classes 也可以针对一或多个类型被参数化。用来管理「各种 不同类型的元素」的 container classes(容器类别)就是典型例子。运用 class templates 你可以实 作出可包容各种类型的 co...
阅读全文
摘要:max.hpp/* The following code example is taken from the book * "C++ Templates - The Complete Guide" * by David Vandevoorde and Nicolai M. Josuttis, Add...
阅读全文
摘要:为什么使用 Templates?C++ 要求我们使用各种特定类型(specific types)来声明变量、函数和其它各种实体(entities); 然而,很多用以处理「不同类型之数据」的程序代码看起来都差不多。特别是当你实作算法(像是quicksort),或实作如 linked-list 或 bi...
阅读全文
摘要:每一位 C++ 程序员都有自己的一套编程风格。这就引来了各种问题:哪儿应该 插入空白符号、怎么摆放分隔符(大括号、小括号)…等等。我们尽量保持全书风格一致, 当然有时候我们也对特殊问题作出让步。例如在教本(初阶)部份我们鼓励以空白符号和较具体的命名方式提高程序可读性,而在高阶主题中,较紧凑的风格可能...
阅读全文