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

时间:2013-12-19 21:34:41

标签: c++ templates

假设:

//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)

1 个答案:

答案 0 :(得分:5)

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