如何结束模板图层
how to end-up template layers?
当
template <typename Super>
class Whatever : public Super
{
...
};
是可能的,创建Whatever
类没有派生的东西?
这是较轻的版本吗?
struct BlankType{};
Whatever<BlankType> w;
////////////////////////////////////////
一些背景:我有我的代码组成的模板层像上面的Whatever
。所以我可以输入:
typedef Whatever<Whenever<Wherever<>>>> MyCombinedType
实际上我不能。我必须做
typedef Whatever<Whenever<Wherever<BlankType>>>> MyCombinedType
,类型也变为BlankType。我不能让Wherever
"不可分层",因为当我做的只是
typedef Whatever<Whenever<>>> MyCombinedType
如果您想创建Whatever
类,而不是从派生的东西,您可以简单地定义其规范如下:
class BlankType {};
template<typename T = BlankType> class Whatever : public T {};
template<> class Whatever<BlankType> {};
有点跑题了,在使用可变模板的c++中,由于递归定义,您可以避免递归实例化:
template <class ...Bases> class Whatever;
template <class B, class ...Bases>
class Whatever<B, Bases...> : public B, public Whatever<Bases...> { /* ... */ };
template <class B>
class Whatever<B> : public B { /*... */ };
template <> class Whatever<> { /* ... */ };
现在你可以输入Whatever<Foo, Bar, Baz>
并从所有这些继承。如果您还想从多个嵌套的Whatever
的其他实例继承,您应该使所有的继承都是虚拟的。
Whatever
,使其不从任何东西派生。如果你写Whatever<> x;
,你有一个类的对象,它不从任何东西派生。
相关文章:
- 如何在千层面打印隐藏图层的输出
- 使用几何着色器的图层渲染似乎只输出图像数组的第一层
- 图层不会绘制另一个图层
- 在作为表后面图层的标签上绘图
- 在 caffe 中仅编译一个图层文件
- 如何在咖啡中提取图层的斑点信息?
- 如何在 c++ 中获取图层的顶部标签?
- 在 Cocos2D-X 中创建具有新成员的图层
- 面向对象的图层
- 跨多个图层的模板化类未知类型
- 如何从装饰项中删除图层
- 存储 SDL 渲染器的预定义图层
- X11 图层管理器
- QGraphicsView上的图层
- 图层下降和更新咖啡模型
- 错误:从类型为"图层"的表达式初始化类型"LineLayer&"的引用无效
- 如何结束模板图层
- 如何创建包含不同图层的 PDF 文件
- 我如何在cocos2d-x中获得相同场景中的其他图层?
- 在cocos2d-x中使用许多图层进行触摸处理