Assignment operator inheritance

前端 未结 6 1128
[愿得一人]
[愿得一人] 2020-11-29 04:09

There is this code:

#include 

class Base {
public:
    Base(){
        std::cout << \"Constructor base\" << std::endl;
    }
            


        
6条回答
  •  心在旅途
    2020-11-29 04:45

    You don't have a default

    Derived& operator=(const Base& a);
    

    in your Derived class.

    A default assignment operator, however, is created:

    Derived& operator=(const Derived& a);
    

    and this calls the assignment operator from Base. So it's not a matter of inheriting the assignment operator, but calling it via the default generated operator in your derived class.

提交回复
热议问题