C++学习06
侯捷C++面向对象编程(下)课程打卡 Day6 4. specialization 特化 4.1 全特化 full specialization 模板是泛化,特化是泛化的反面,可以针对不同的类型,来设计不同的东西 其语法为template<> struct xxx<type> template<> struct hash<char> { ... size_t operator()(char& x) const {return x;} }; template<> struct hash<int> { ... size_t operator()(int& x) const { return x; } }; 这里编译器就会用 int 的那段代码;注意:hash<int>() 是创建临时变量 cout << hash<int>()(1000) 4.2 偏特化 partial specialization 4.2.1 个数上的偏 例如:第一个模板参数我想针对 bool 特别设计 ...