具有部分专用化的模板子类
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 模板
http://en.cppreference.com/w/cpp/language/type_alias
相关文章:
- 继承期间显示未知行为的子类
- 通过指向指针数组的指针访问子类的属性
- 从父类方法返回子类对象
- c++, 在子类中,如何在没有对象的情况下访问父类的方法?
- 将父类对象强制转换为子类的问题
- 避免在C++中重复子类定义
- 将QOpenGLWidget子类转换为使用Metal而不是OpenGL的子类是否可行?
- 如何初始化矢量的模板化子类
- C++ 继承:将子类传递给需要基类的函数并获取子类行为
- 如何检查模板专用化是否是基本模板的子类?
- 是具有接口专用化的子类多态的模板实例化
- 在子类中定义可变参数函数专用化
- 模板专用化子类
- C++ 使类的成员变量成为子类中的专用化
- 模板化子类和模板化基类的静态成员专用化
- X 的任何子类的专用类模板,无需向模板添加其他类型参数
- 模板基类子类的模板专用化
- 如何在类模板的子类中使用专用化
- 编写专用于类及其子类的函数模板
- 子类的专用模板