c++ polymorphism of operator overloading

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

    If you are searching for a standard operator+() implementation, then unfortunately that is impossible:

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

    This code cannot compile, because the compiler cannot return an abstract X class by value.

提交回复
热议问题