假设:
//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)
答案 0 :(得分:5)
template int Demo<double>::convert<int>(const double &);