[英]C++ template class with static class member
I am new to template programming. 我是模板编程的新手。 I have a vector class that I am attempting to template that contains static members of the same class as the parent:
我正在尝试对一个向量类进行模板化,该向量类包含与父类相同的静态成员:
template<typename T>
class Vector
{
// vector stuff
static const Vector c_NullVector;
}
I am attempting to initialize this static member but can only achieve success if I explicitly state the type, eg: 我正在尝试初始化此静态成员,但只有在我明确声明类型的情况下才能成功,例如:
const Vector2d<float> Vector2d<float>::c_Zero(0.0);
I would rather not have to initialize each type if possible. 如果可能的话,我宁愿不必初始化每种类型。 Is this even possible?
这有可能吗?
You must provide a definition as follows: 您必须提供如下定义:
template<typename T>
class Vector
{
// vector stuff
static const Vector c_NullVector;
}
template <typename T>
const Vector<T> Vector<T>::c_NullVector;
If you can come up with a generic initialisation, you can put it in the definition. 如果可以提出泛型初始化,则可以将其放入定义中。
I doubt, that's possible. 我怀疑,那是可能的。 What about
Vector<MyVeryComplicatedClass>
? Vector<MyVeryComplicatedClass>
呢? How would you know how to initialize it? 您怎么知道如何初始化它?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.