在模板派生类中使用声明不能被g ++识别

时间:2016-10-18 11:57:28

标签: c++ c++11 gcc

以下代码无法使用g ++ 4.9,5.4和6.2进行编译。

template <class T, int M, int N>
struct Matrix { };

template <typename T> struct Traits;
class Derived;

template <>
struct Traits<Derived>
{
  static constexpr int N= 3;
};

template <typename T>
class Base: public Traits<T>
{
protected:
  using Traits<T>::N;
  static const Matrix<double,N,N> Mat;
};

template <typename T>
const Matrix<double,Base<T>::N,Base<T>::N> Base<T>::Mat;

class Derived: public Base<Derived> {};

int main()
{
Derived foo;
}

我收到错误消息‘const Matrix<double, #‘using_decl’ not supported by dump_expr#<expression error>, #‘using_decl’ not supported by dump_expr#<expression error>, (AutoAlign | (((#‘using_decl’ not supported by dump_expr#<expression error> == 1) && (#‘using_decl’ not supported by dump_expr#<expression error> != 1)) ? RowMajor : (((#‘using_decl’ not supported by dump_expr#<expression error> == 1) && (#‘using_decl’ not supported by dump_expr#<expression error> != 1)) ? ColMajor : ColMajor))), #‘using_decl’ not supported by dump_expr#<expression error>, #‘using_decl’ not supported by dump_expr#<expression error> > Base<T>::Mat

我不明白出了什么问题。有人可以帮忙吗?

解决方法包括:

template <typename T>
class Base: public Traits<T>
{
protected:
  static constexpr auto N= Traits<T>::N;
  static const Matrix<double,N,N> Mat;
};

0 个答案:

没有答案