Assignment operator not available in derived class

后端 未结 4 1309
甜味超标
甜味超标 2021-01-03 19:02

The assignment operator in base class does not seem to be available in derived class. Given this code:

#include 

class A{
    int value;
pub         


        
4条回答
  •  感情败类
    2021-01-03 19:24

    Every class has at least one assignment operator implicitly defined when we don't provide one ourselves.

    And when a member function in a derived class is defined with the same name as a member in the base class, it hides all the base class definitions for that name.

    You can use a using declaration, but be warned that it will pull all the members named operator= and allow code like this:

    A a;
    B b;
    b = a;
    

    Which is slightly dubious.

提交回复
热议问题