Skip to content

Instantly share code, notes, and snippets.

@flomnes
Created August 26, 2024 13:49
Show Gist options
  • Save flomnes/d39b3b59a415edadb78c0b0be7994a3b to your computer and use it in GitHub Desktop.
Save flomnes/d39b3b59a415edadb78c0b0be7994a3b to your computer and use it in GitHub Desktop.
Default operator error
class EmptyClass
{
virtual ~EmptyClass() = default;
};
class DerivedFromEmpty: public EmptyClass
{
bool operator==(const DerivedFromEmpty&) const = default;
};
// g++ -std=c++20 -c default.cc
// default.cc:6:7: error: deleted function ‘virtual DerivedFromEmpty::~DerivedFromEmpty()’
// overriding non-deleted function
// 6 | class DerivedFromEmpty: public EmptyClass
// | ^~~~~~~~~~~~~~~~
// default.cc:3:13: note: overridden function is ‘virtual constexpr EmptyClass::~EmptyClass()’
// 3 | virtual ~EmptyClass() = default;
// | ^
// default.cc:6:7: note: ‘virtual DerivedFromEmpty::~DerivedFromEmpty()’ is implicitly deleted
// because the default definition would be ill-formed:
// 6 | class DerivedFromEmpty: public EmptyClass
// | ^~~~~~~~~~~~~~~~
// default.cc:6:7: error: ‘virtual constexpr EmptyClass::~EmptyClass()’ is private within this
// context default.cc:3:13: note: declared private here
// 3 | virtual ~EmptyClass() = default;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment