我有一个带有模板构造函数的模板结构:
template<typename F>
struct Vector2
{
template<typename F1>
Vector2(const Vector2<F1>& vector);
};
实施:
template<typename F>
template<typename F1>
Vector2<F>::Vector2(const Vector2<F1>& vector)
: Vector2(vector.x, vector.y)
{}
可以为 Vector2
template struct Vector2<float>::Vector2(const Vector2<float>& vector);
// Errors: "Expected unqualified-id" and "Expected ')'"
template struct Vector2<float>::Vector2<float>(const Vector2<float>& vector);
// Errors: same as in the previous one
template struct Vector2::Vector2(const Vector2<float>& vector);
// Error: "Use of class template 'Vector2' requires template arguments"
如果你想显式实例化类模板
template struct Vector2<float>;
如果你想显式实例化一个类成员模板
template Vector2<float>::Vector2(const Vector2<float>& vector);