I, like so many others, am writing a linear algebra library for my personal use. In doing so, I’m trying to learn more about programming with templates in C++. I have a class, which goes something like
template<typename T, size_t N, size_t M = N>
class Matrix
{
...
}
Now, there are certain operations that I would like to restrict to square matrices (determinant, for example). But when I try to add:
T Determinant<T,N,N>();
It fails to compile, with the error being “Missing ‘;’ before ‘<‘”. I’ve tried adding another template above the determinant call, without any success. Any advice on how to accomplish this would be very much appreciated.
Unfortunately, you cannot specialize a function for specific template parameters like that, you have to do the whole class. Since you don’t want to re-code the entire thing, you probably want to use inheritance.