03 2020 档案
摘要:1. 继承是动多态 2.模板是静多态(ploy.cpp ploy .hpp) ploy.hpp #include <cstdlib>#include <vector>#include <iostream>class Coord { private: int x, y; public: Coord (
阅读全文
摘要:print.hpp #ifndef __LINK_HPP#define __LINK_HPP#include <iostream>#include <typeinfo>template<typename T>void print(T const&);#include "print.cpp"templ
阅读全文
摘要:#include <iostream>#include <string>#include <typeinfo> #define HH 1 #ifdef HHtemplate<typename T>inline T const& max(T const& a, T const& b){ return
阅读全文
摘要:模板如果用内建类型初始化,怎么保证变量得到合适的初始化? template<typename T> void foo() { T x;//不能初始化 } 应该这样 template<typename T> void foo() { T x = T();//合适的初始化 } 同样对于类模板 templ
阅读全文
摘要:#include <iostream>#include <deque>#include <stdexcept>#include <memory>#include <vector>template<typename T, template<typename ELEM, typename = std::
阅读全文
摘要:#include <string>#include <iostream>#include <stdexcept> template<typename T, int MAXSIZE>//template<typename T = int, int MAXSIZE = 100>//可以指定默认值!!!c
阅读全文
摘要:http://www.josuttis.com/tmplbook/toc.html
阅读全文
摘要:1. 特化类模板的意义:通过特化类模板可以优化基于某种特定类型的实现, 或者克服某钟特定类型在实例化类模板时所出现的不足。 2. 如果要特化一个类模板,还要特化盖类模板的所有成员函数。虽然可以只特化某个成员函数, 但是这样没有特化整个类,也就没有特化整个类模板。
阅读全文
摘要:1. 类模板中要自己实现拷贝构造和赋值构造函数的话,应该这样编写 template<typename T> calss Stack { ... Stack(Stack<T> const&);//使用类型时,只用Stack。后边参数使用类的类型要加上模板参数T Stack<T> &operator=(
阅读全文
摘要:1.当使用函数模板并且引起模板实例化的时候,编译器需要查看模板的定义 2.template<typename T1, typename T2>//实参演绎 inline T1 max(T1 const& a, T2 const& b)//注意函数模板的返回类型只能是T1,不能是T1&,因为有可能返回
阅读全文