0
template <typename T, unsigned D>
class Matrix
{
 public:
  T Determinant( void ) const;

  T m[D][D];
};


template <typename T>
T Matrix<T, 2>::Determinant( void ) const
{
  return m[0][0] * m[1][1] - m[1][0] * m[0][1];
}

Hello, forum. I have this code, yet I get error:

1>c:\dropbox\projects\math\matrix.h(319): error C3860: template argument list following class template name must list parameters in the order used in template parameter list
1>c:\dropbox\projects\math\matrix.h(319): error C2976: 'Math::Matrix<T,D>' : too few template arguments

No Idea what is wrong. Please help.

user2883715
  • 547
  • 4
  • 14
  • I believe you can only specialize the entire class, not individual functions. – Adam Oct 27 '13 at 05:45
  • possible duplicate of ["invalid use of incomplete type" error with partial template specialization](http://stackoverflow.com/questions/165101/invalid-use-of-incomplete-type-error-with-partial-template-specialization) – n. m. could be an AI Oct 27 '13 at 05:55
  • What you can do is make `Determinant` a non-member (possibly a friend) and *overload* it. – n. m. could be an AI Oct 27 '13 at 05:57

2 Answers2

2

You need to provide the definition for that class specialization. For instance:

template <typename T, unsigned D>
class Matrix
{
 public:
  T Determinant( void ) const;

  T m[D][D];
};

template <typename T>
class Matrix <T, 2>
{
  T m[2][2];    

public:
  T Determinant (void) const;
};

template <typename T>
T Matrix<T, 2>::Determinant (void) const
{
  return m[0][0] * m[1][1] - m[1][0] * m[0][1];
}

Without that, the compiler won't be able to tell if the specialized version of Matrix<T, 2> contains a Determinant method.

greatwolf
  • 20,287
  • 13
  • 71
  • 105
0

This is a possible duplicate of c++ template partial specialization member function

As mentioned there, you do not specialize methods, but the class itself.

Community
  • 1
  • 1
battery
  • 502
  • 6
  • 26