Unsolved no out-of-line virtual method definitions
-
Hi, this struct
struct InterfaceA { virtual void Clean() {} InterfaceA() {} virtual ~InterfaceA() {} };
emits the warning
warning: 'InterfaceA' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit
Can someone explain how to resolve?
-
@mrdebug See https://stackoverflow.com/questions/28786473/clang-no-out-of-line-virtual-method-definitions-pure-abstract-c-class?rq=1
// B::x() is inline in the class definition. struct B { virtual void x() { } virtual ~B() { } };
If you move the destructor body to the cpp file the warning should disappear.
-
Perfect and now
.h struct DefaultStructInterface { DefaultStructInterface() {} virtual ~DefaultStructInterface(); virtual void Clean() {} };
but the line of code
.cpp DefaultStructInterface::~DefaultStructInterface() {}
causes
warning: definition of implicit copy assignment operator for 'DefaultStructInterface' is deprecated because it has a user-declared destructor
-
Hi
Are you using the clang compiler ?
anyway, this might be interesting
https://stackoverflow.com/questions/51863588/warning-definition-of-implicit-copy-constructor-is-deprecated -
@mrdebug said in no out-of-line virtual method definitions:
is deprecated because it has a user-declared destructor
This is just the good old rule-of-3 (now became rule-of-5). why don't you just
=default
them instead of having an empty body to avoid headakes?