c++ polymorphism of operator overloading

前端 未结 6 1745
梦谈多话
梦谈多话 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:52

    Note : Question have been updated, making this answer less valid.

    If you're description is correct, you're just forgetting to use the virtual keyword to specify the operator as virtual...

    class Addable{
    public:
        virtual int operator+ const ( const Addable& other ) = 0; // pure virtual
        virtual int operator+ const ( int number ) = 0; // pure virtual
    };
    

提交回复
热议问题