(c + +) Interview in English-virtual

Source: Internet
Author: User

Q:What is virtual function?
A:A virtual function or virtual method is A function or method whose behavior can being overridden within an inheriting clas s by a function with the same signature. This concept is a important part of the polymorphism portion of object-oriented programming (OOP)

Q:What is a "pure virtual" member function?
A:The abstract class whose pure virtual method have to is implemented by all the classes which derive on these. Otherwise It would result in a compilation error. This construct should is used when one wants to ensure so all the derived classes implement the method defined as pure V Irtual in base class.

Q:How virtual functions is implemented C + +?

A:virtual functions is implemented using a table of function pointers, called the vtable. There is one entry in the table per virtual function in the class. This table was created by the constructor of the class. When a derived class was constructed, its base class is constructed _rst which creates the vtable. If the derived class overrides any of the base classes virtual functions, those entries in the vtable is overwritten by T He derived class constructor. Should never call virtual functions from a constructor:because the vtable entries for the object could not has been set up by the derived class constructor yet, so-might end up calling base class implementations of those Vir tual functions

(c + +) Interview in English-virtual

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.