【发布时间】:2010-10-27 05:28:42
【问题描述】:
这种模式的目的是什么?这叫什么?我第一次看到它时看起来很奇怪,虽然我现在已经看过很多次了。
template<typename Derived>
struct Base {
//...
};
struct Example : Base<Example> {
//...
};
【问题讨论】:
标签: c++ templates terminology crtp static-polymorphism
这种模式的目的是什么?这叫什么?我第一次看到它时看起来很奇怪,虽然我现在已经看过很多次了。
template<typename Derived>
struct Base {
//...
};
struct Example : Base<Example> {
//...
};
【问题讨论】:
标签: c++ templates terminology crtp static-polymorphism
它被称为Curiously Recurring Template 模式,允许静态多态性。
当您想向特定类添加功能但希望实用程序在一般情况下可用时,它很有用。通过使实用程序依赖并使用模板参数,您可以实现两者。
【讨论】:
Curiously Recurring Template Pattern,或者我们call it的CRTP。
【讨论】: