简体   繁体   中英

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?

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
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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