Pure virtual function call

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.