C ++ template: curiously recurring template pattern-crtp)

Source: Internet
Author: User

 

C ++: prefer curiously recurring template pattern (crtp) to template pattern: http://www.codeproject.com/Tips/537606/Cplusplus-Prefer-Curiously-Recurring-Template-Patt

 

The "template pattern" defined in the "gof" design pattern has nothing to do with the c ++ template. It is a behavior pattern.

Crtp is an improvement based on the template mode. It is a C ++ idiom: Class X inherits from the base class template instance, the template instance uses X as the template parameter. This idiom name was created by Jim coplien, which was observed in some early C ++ template code. This technique can achieve the same effect as using virtual functions, but there is no (runtime) additional loss of dynamic polymorphism (and some elastic loss ). Crtp can be used as an alternative to the template mode to provide dynamic polymorphism-not required during runtime. This mode is widely used in Windows ATL/wtl libraries.

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.