c++ polymorphism of operator overloading

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

     #include 
    using namespace std;
    class ana {
        protected :
        int x;
        public :

    virtual int operator+()=0; virtual void operator=(ana&)=0; };

    class baba:public ana{ public: baba(int k){x=k;} int operator+(baba &ali){ int k; k=x+ali.x; return k; } void operator=(baba &ali){ x=ali.x; }

    };
    

    int main(){ baba k(4);

    return 0; }what is wrong here?

提交回复
热议问题