Implementation of generic technology

Source: Internet
Author: User
There are many implementation methods for generic technology, such as templates and polymorphism.

The template is determined by the compile time, the polymorphism is determined by the runtime, and the others such as rtti are also determined by the runtime.

It is best to use a template. polymorphism depends on the Table query during running of virtual tables.

For example, if a class has a virtual method, the memory start address of the instance of this class is the virtual table address. You can forcibly convert the memory start address to int * to obtain the virtual table, then (int *) * (int *) gets the memory address of the first function in the virtual table, and converts it to the function type forcibly, that is, it can be called to verify the virtual table mechanism.

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.