简体   繁体   English

C++ 模板 inheritance 2 arguments

[英]C++ template inheritance 2 arguments

is it possible to inherit everything from template class and just rewrite some of it's functions specialized to int, double or float?是否可以从模板 class 继承所有内容,并仅重写其中一些专用于 int、double 或 float 的函数?

Is there a way to write something similar to this?有没有办法写出类似的东西?

template<typename T, size_t N>
class Container<int, N> : public Container<T, N> {

};

No, you need to use a different name.不,您需要使用不同的名称。

template<class T, size_t N>
struct ContainerBase:std::array<T,N> {
  // some methods here
};

template<class T, size_t N>
struct Container:ContainerBase<T,N> {
  // inherit any constructors:
  using ContainerBase<T,N>::ContainerBase;
};
template<size_t N>
struct Container<int, N>:ContainerBase<int,N> {
  using ContainerBase<int,N>::ContainerBase;
  // overload (not override) methods here
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM