i have 2 classes:
class { public: virtual void somefunction() = 0; }; class b : public { public: b(); ~b(); void somefunction(); }; b::b() {} void b::somefunction() { // code }
but g++ errors:
class has virtual functions , accessible non-virtual destructor class b has virtual functions , accessible non-virtual destructor
i don't have idea error is... somewhere on blogs read it's compiler warning. how can fix problem?
this happens because base class a
not have virtual destructor. instance, if had code:
int main() { a* = new b; delete a; }
then delete a
call not able call b
's destructor because a
's isn't virtual. (it leak of b
's resources.) can read more virtual destructors here.
add virtual destructor base class , should fine.
class { public: virtual void somefunction() = 0; virtual ~a() = 0; }
Comments
Post a Comment