提问者:小点点

C++模板继承2参数


有没有可能继承模板类的一切,只是重写一些专门用于int,double或float的函数?

有没有办法写出类似这样的东西?

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

};

共1个答案

匿名用户

不,你得换个名字。

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

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(c++|模板|继承|参数)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?