Effective C + + clause 41 Understanding implicit interface and compile-time polymorphism

Source: Internet
Author: User

1. Object-oriented programming usually solves problems with explicit interfaces (function prototypes in classes) and run-time polymorphism (virtual functions and Rtti), but in the world of templates and generics programming, the importance of implicit interfaces and compile-time polymorphism is significantly increased, although explicit interfaces and runtime polymorphism still exist.

2. Usually explicit interfaces are composed of function signatures, and implicit excuses are not based on function declarations, but on valid expressions.

Implicit interfaces in the so-called generic programming refer to the operations involved in a type parameter inside a function template or member function within a class template. That is, the type parameter must support the operations within the function template, such as operator>,operator!=, and for different types, The specific behavior of operator> and other operations is not the same, its present behavior occurs in the compilation period, which together with the template in the compilation period to form a "compile-time polymorphism."

3. The implicit interface added to the template parameter, like an explicit interface added to a class object, is checked at compile time, so it is as if the object cannot be used in a way that "explicitly interfaces with classes" and cannot be used in the template. Objects that do not support the implicit interface required by template (both do not compile).

Effective C + + clause 41 Understanding implicit interface and compile-time 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.