来自基类的Owerride运算符

时间:2017-04-03 12:16:35

标签: c++ class operator-overloading

我有两个A和B类。我想要B类范围A并添加z参数。

template<typename T>
class A
{
 public:
    A()
    {}

    ~A(){}
    virtual bool operator<(const A<T>& lhs) const
    {
        return ( (x < lhs->getX()) && (y < lhs->getY()) );
    }
    const T getX()
    {
     return x;   
    }

    const T getY()
    {
        return y;
    }
private:
    const T x;
    const T y;


};


template<typename T,typename  Z>
class B: public   A<T>
{
 public:
   B()
    {}

    ~B(){}
    bool operator<(const B<T,Z>& lhs) const
    {
        return ( (x < lhs->getX()) && (y < lhs->getY()) , (z < lhs->getZ()));
    }

    const T getZ()
    {
        return z;
    }
private:
    const T z;

};

我尝试编译它但不起作用。我在下面列出错误:

In member function 'bool B<T, Z>::operator<(const B<T, Z>&) const': 
40:13: error: 'x' was not declared in this scope 
40:34: error: 'y' was not declared in this scope

我想重载运算符&lt;在B班。怎么可能?我使用的是C ++ 14编译器。

0 个答案:

没有答案