简体   繁体   English

成员初始值设定项不命名非静态数据成员

[英]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.

相关问题 当初始值设定项是基类名称时出现错误“初始值设定项未命名非静态数据成员或基类” - Error 'initializer does not name a non-static data member or base class' when the initializer is the base class name 成员初始化程序“ SuperClass”未命名非静态数据成员或基类 - member initializer 'SuperClass' does not name a non-static data member or base class 成员初始化程序列表和非静态数据成员上的默认成员初始值设定项之间的区别是什么? - What's the differences between member initializer list and default member initializer on non-static data member? 部分聚合初始化和非静态数据成员初始化程序 - Partial Aggregate Initialization and Non-static Data Member Initializer 非静态数据成员初始值设定项中lambda函数的分段错误 - Segmentation fault for lambda function in non-static data member initializer 来自另一个非静态的非静态成员初始化程序 - Non-static member initializer from another non-static 是否允许在默认成员初始化程序中调用非静态成员 function? - Is it allowed to call a non-static member function in a default member initializer? 模板类和继承问题-“列表”未命名非静态数据成员或基类 - Issues with template classes and inheritance - 'List' does not name a non-static data member or base class 为什么静态数据成员不能与非静态数据成员具有相同的名称? - Why can't a static data member has the same name with non-static data member? 从非静态成员初始化静态数据成员 - Initializing static data member from non-static member
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM