在这个例子中为什么我需要CRTP? [英] In this example why do I need CRTP?

查看:138
本文介绍了在这个例子中为什么我需要CRTP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参阅对象计数器示例此处:为什么它不会继承非模板类计数器。为什么计数器应该是模板?

See Object counter example here: Why it just does not inherit from non-template class counter. Why counter should be template?

template <typename T>
struct counter


推荐答案

counter 用于不同类型。

请注意,这些计数器是静态数据成员,因此在给定特化的所有实例之间共享。

Specializations will give you different counters for different types.
Note that those counters are static data members, thus shared among all instances of the given specialization.

这篇关于在这个例子中为什么我需要CRTP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆