c++ polymorphism of operator overloading

前端 未结 6 1756
梦谈多话
梦谈多话 2021-01-02 04:02

How can I make pure virtual function a operator+(); function. wheh ı do like this in base class int operator+()=0; compiler gives error . in derive class operator+() funct

6条回答
  •  遥遥无期
    2021-01-02 04:44

    The syntax for a pure virtual function would be something like:

    class X { 
    public:
         virtual int operator+(X const &rhs) = 0;
    };
    

    Note, however, that you only rarely want to do this -- you typically want an overload of operator+ to be implemented as a free function, to allow conversion of the left operand (if necessary).

提交回复
热议问题