来自维基百科:
// The Curiously Recurring Template Pattern (CRTP)
template <typename T>
struct base
{
// ...
};
struct derived : base<derived>
{
// ...
};
现在,如果我愿意derived_from_derived
,我可以写:
// The Curiously Recurring Template Pattern (CRTP)
template <typename T>
struct base
{
// ...
};
template <typename T>
struct derived : base<T>
{
// ...
};
struct derived_from_derived : derived <derived_from_derived>
{
// ...
};
现在假设我只想要一个derived
对象。这不起作用:
derived<derived> obj;
derived
必须是抽象的,还是有办法实例化它?