当有:
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++ - 如何结束模板层?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6982689/