Can someone tell me how to get rid of the compiler warning for this code?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include <memory>
class LivingBeing {
int ID;
public:
LivingBeing() = default;
virtual ~LivingBeing() = default;
LivingBeing (int id): ID (id) {}
private:
virtual LivingBeing& assign (const LivingBeing&) = 0;
};
class CharacterClass: virtual public LivingBeing {
int level;
public:
CharacterClass (int lev): level (lev) {}
};
template <typename DERIVED> class LivingBeingCRTP: virtual public LivingBeing {
protected:
virtual LivingBeing& assign (const LivingBeing& being) override {
return static_cast<DERIVED&>(*this) = dynamic_cast<const DERIVED&>(being);
}
};
class SpellCastingClass: virtual public LivingBeing {
protected:
void establishSpellsKnown();
};
class SpellCastingClass1: virtual public SpellCastingClass {};
class SpellCastingClass2: virtual public SpellCastingClass {};
class MultiClass: public CharacterClass, public SpellCastingClass1, public SpellCastingClass2,
public LivingBeingCRTP<MultiClass> {
public:
MultiClass (int id, int level): LivingBeing (id), CharacterClass (level) {
establishSpellsKnown();
}
};
int main() {}
|
The compiler warning I'm getting (which I worry will run into problems later when moving objects) is:
C:\DandD>g++ -std=c++11 Test.cpp -Wall -pedantic
Test.cpp: In instantiation of 'LivingBeing& LivingBeingCRTP<DERIVED>::assig
n(const LivingBeing&) [with DERIVED = MultiClass]':
Test.cpp:33:13: required from here
Test.cpp:25:7: warning: defaulted move assignment for 'SpellCastingClass1'
calls a non-trivial move assignment operator for virtual base 'SpellCasting
Class' [-Wvirtual-move-assign]
class SpellCastingClass1: virtual public SpellCastingClass {};
^
Test.cpp:26:7: warning: defaulted move assignment for 'SpellCastingClass2'
calls a non-trivial move assignment operator for virtual base 'SpellCasting
Class' [-Wvirtual-move-assign]
class SpellCastingClass2: virtual public SpellCastingClass {};
I don't know what the problem is really. Currently, SpellCastingClass1 and SpellCastingClass2 need to be virtual derived classes (else I run into ambiguity error with establishSpellsKnown()). I need a solution that does not change them being virtual. Do I have to write a move assignment operator in one of the classes? Removing LivingBeingCRTP<DERIVED>::assign removes the warning, but I need that function though.