c++ - why we should implement pure virtual function in this case? -
my code:
class { public: a(){} a(int _a) : a(_a){} virtual ~a() = 0; private: int a; }; class b : public { public: b(){} b(int _a):a(_a){} ~b(){} private: };
i declare b b;
, when compile program, met error:
error lnk2019: unresolved external symbol "public: virtual __thiscall a::~a(void)" (??1a@@uae@xz) referenced in function "public: virtual __thiscall b::~b(void)" (??1b@@uae@xz)
i want know, need implement pure virtual function time?
in general not need implement pure virtual function. indeed that's sort of point. however, destructors do, because not acceptable destructor have no implementation. because unlike regular virtual methods, most-derived 1 used @ runtime, virtual destructors in inheritance chain called, most- least-derived, fields of derived object may destroyed.
for reason may preferable not make pure virtual destructors, except in cases necessary (i.e. when have base class must abstract has no other virtual methods made pure).
Comments
Post a Comment