[英]Member initializer does not name a non-static data member
I am new to C++ and trying to get an open source C++ project to compile in x-code. 我是C ++的新手,并试图让一个开源的C ++项目在x-code中编译。 The last two lines of this code:
这段代码的最后两行:
template<typename T>
struct TVector3 : public TVector2<T> {
T z;
TVector3(T _x = 0.0, T _y = 0.0, T _z = 0.0)
: TVector2(_x, _y), z(_z)
are throwing the error: Member initializer does not name a non-static data member 抛出错误:成员初始值设定项未命名非静态数据成员
Based on ( member initializer does not name a non-static data member or base class ), I tried changing the code to this: 基于( 成员初始化程序没有命名非静态数据成员或基类 ),我尝试将代码更改为:
template<typename T>
struct TVector3 : public TVector2<T> {
T z;
TVector3(T _x = 0.0, T _y = 0.0, T _z = 0.0)
: TVector2(_x, _y)
{ z(_z);}
But I am getting the same error. 但我得到了同样的错误。 Here is the code for the super-class, Vector2.
这是超类Vector2的代码。 How can I resolve this error?
我该如何解决这个错误?
struct TVector2 {
T x, y;
TVector2(T _x = 0.0, T _y = 0.0)
: x(_x), y(_y)
{}
double Length() const {
return sqrt(static_cast<double>(x*x + y*y));
}
double Norm();
TVector2<T>& operator*=(T f) {
x *= f;
y *= f;
return *this;
}
TVector2<T>& operator+=(const TVector2<T>& v) {
x += v.x;
y += v.y;
return *this;
}
TVector2<T>& operator-=(const TVector2<T>& v) {
x -= v.x;
y -= v.y;
return *this;
}
};
Inside a class template, only its own name is injected for use without template arguments. 在类模板中,只注入自己的名称而不使用模板参数。 You need this:
你需要这个:
template<typename T>
struct TVector3 : public TVector2<T> {
T z;
TVector3(T _x = 0.0, T _y = 0.0, T _z = 0.0)
: TVector2<T>(_x, _y), z(_z)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.