Inheritance and interface 1

Source: Internet
Author: User

What is output by the following program:

# Include <iostream> using namespace STD; Class A {public: void virtual F () {cout <"A" <Endl ;}}; Class B: public A {public: void virtual F () {cout <"B" <Endl ;}}; int main () {A * pA = new (); // defines a pointer Pa of type A. Pa points to Class A pa-> F (); B * pb = (B *) Pa; // defines a pointer of type B, Pb also points to type a Pb-> F (); Delete Pa, PB; // deletes the addresses pointed to by PA and Pb, however, the pointer type of PA and Pb is still the PA of Class A = new B (); // PA points to Class B pa-> F (); Pb = (B *) Pa; pb-> F (); Return 0 ;}

This topic mainly deals with the problem of overwriting virtual functions. Virtual functions are covered by functions with the same name in the quilt class.


The output result is AABB.

This article is from the "7883538" blog, please be sure to keep this source http://7893538.blog.51cto.com/7883538/1433391

Related Article

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.