[英]template subclassing with partial specialization
考虑以下
template<typename Type, size_t Dimensions>
struct Base
{
Base(/*some args*/) { /*do something*/ }
};
template<size_t Dim>
class Derived : Base<double,Dim> {};
派生不继承Base的构造函数,因为它表明Base是部分专业化,因此需要一些不同的构造函数。 但是,就我而言,情况并非如此。 我主要希望它在不同情况下具有不同的名称。 我正在寻找与宏或以下宏(如果存在)不同的解决方案。
template<size_t Dim>
struct Derived
{
typedef Base<double, Dim> Type;
}
主要是因为我不喜欢使用
Derived<n>::Type
到处都是,不确定我要
typedef Derived<n>
我使用的每n个。
尝试这个:
template<std::size_t dim>
using foo = typename derived<dim>::type;
//usage
foo<n> bar;
这利用了C ++ 11模板的using语句
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.