A question about polymorphism.

Source: Internet
Author: User

Learning polymorphic time, encountered such a problem, in the beginning, I think the answer will be "seven Dwarft", "Disneymovie", "Seven Dwarfts", "Miki Mouse"

Then, I experimented with VS2013 in person.

The results are as follows:

Not the same as I expected, then read through the books, I know. For example, A objecta = new D (); This line of statement, the implementation of the process is, new () will be

First Find, Class D, the base class A, see the function is virtual, and then along the inheritance relationship down, find the first override, is Objectb.movie (), so this sentence

The execution result of the statement is Disneymovie

A question about polymorphism.

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.