C + + interview Quiz guide

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/charles_r_chiu/article/details/47858885

1. What is a virtual function? What is a pure virtual function?
For:
The virtual function declaration is as follows: Virtual returntype functionname (Parameter); Virtual functions are introduced for dynamic binding
The pure virtual function declaration is as follows: Virtual returntype functionname () = 0; Pure virtual functions are introduced to derive interfaces.

2
, why do the base classes need virtual destructors?
A: The standard rule: when the derived class is deleted by a base class pointer, and the destructor for the base class is non-virtual, the
Undefined behavior. Typically a resource leak occurs.
The workaround is to declare a virtual destructor for the polymorphic base class.

C + + interview Quiz Guide (GO)

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.