模板类上的模板函数的实例化

instanation of template function on template class

本文关键字:实例化 函数      更新时间:2023-10-16

给定:

//hpp
template <typename T>
struct Demo {
    template<typename U>
    U convert(const T &t); 
};
//cpp
template <typename T>
template <typename U>
U Demo<T>::convert(const T &t) {
        return static_cast<U>(t);
}

如何在 CPP 中显式实例化模板?(例如 T 是双精度,U 是 int)

template int Demo<double>::convert<int>(const double &);