I've following code (I've removed some code not important here):
class State {
public:
virtual void enter() = 0;
virtual void update() = 0;
virtual void exit() = 0;
};
class SimpleState : public State {
public:
SimpleState() = default;
SimpleState(const SimpleState&) = default;
SimpleState(SimpleState&&) = default;
virtual ~SimpleState() = default;
public:
void enter() override;
void update() override;
void exit() override;
public:
SimpleState& operator=(const SimpleState&) = default;
SimpleState& operator=(SimpleState&&) = default;
};
I've added default operators due to solve a guideline warning since I've defined the destructor and I need to define also other stuff (rule of 5 if I remember).
If I build it with Visual Studio 2019 by enabling cpp core guidelines, I obtain the following warnings:
SimpleState.hpp: warning C26456: Operator 'SimpleState::operator=' hides a non-virtual operator 'State::operator=' (c.128).
SimpleState.hpp: warning C26456: Operator 'SimpleState::operator=' hides a non-virtual operator 'State::operator=' (c.128).
I want to get rid of it, so I've changed the code in following way:
class State {
public:
virtual void enter() = 0;
virtual void update() = 0;
virtual void exit() = 0;
public:
virtual State& operator=(const State&) = 0;
virtual State& operator=(State&&) = 0;
};
class SimpleState : public State {
public:
SimpleState() = default;
SimpleState(const SimpleState&) = default;
SimpleState(SimpleState&&) = default;
virtual ~SimpleState() = default;
public:
void enter() override;
void update() override;
void exit() override;
public:
SimpleState& operator=(const SimpleState&) override = default;
SimpleState& operator=(SimpleState&&) override = default;
};
But in that case I obtain the following errors:
SimpleState.hpp: error C3668: 'SimpleState::operator =': method with override specifier 'override' did not override any base class methods
SimpleState.hpp: error C3668: 'SimpleState::operator =': method with override specifier 'override' did not override any base class methods
What I'm doing wrong and how can I remove the guideline warning?