2015-04-08 10:58:19
A pure virtual function is defined in a base class, which is implemented in a derived class.
If you call the change pure virtual function in the constructor or destructor of the base class,
The R6205 error:pure virtual function call will appear
When the object is constructed, the base class constructor is called first, but the derived class object is not yet constructed successfully.
Therefore, the virtual table pointer to the pure virtual function that is called points to the virtual table of the base class, and the pure virtual function of the base class is undefined.
This can also happen if the derived class is called in a fictional function of the base class, and the derivation is destroyed.
1#include <stdio.h>2 3 classBase4 {5 Public:6 Base ()7 {8printf"Base Construction be called...\n");9 Open_func ();Ten } One A voidOpen_func () - { -printf"Base::open_func () be called...\n"); the Show (); - } - - Virtual voidShow () =0; + }; - + classD: PublicBase A { at Public: - D () - { -printf"D Construction be called...\n"); - } - in voidShow () - { toprintf"d::show () be called...\n"); + } - }; the * intMain () $ {Panax Notoginseng d D; - return 0; the}
Pure virtual function call