鲍松山STL源码剖析 SGI版
2023-08-21 18:50 作者:bili_67158895267 | 我要投稿
模板
从模板生成的函数或类的定义是模板的实例或实例化
可以以内联的方式为类模板的成员函数指定一个外部模板
template<typename T>inline Array<T>::Array(cosnt Array& other)try:elements{new T[other.count]},count{other.count}{
for (size_t i = 0; i < count; i++)
{
elements[i] = other.elements[i];
}}catch(bad_alloc&){
cerr<<"memory allocation failed for Array object copy."<<endl;}
每个类模板类型参数需要一个实参,除非有默认实参
Array<int> data{40};