Imbricated C++ template
- by gregseth
I have the following pattern:
template <int a, int b>
class MyClass
{
template <int c>
MyClass<a, c> &operator*(MyClass<c, b> const &other) const;
};
// ../..
template <int a, int b> template <int c>
MyClass<a, c> &MyClass<a, b>::operator*(MyClass<c, b> const &other) const
{
MyClass<a, c> result;
// ..do stuff..
return result;
}
It doesn't compile, the error message is
Error C2975. invalid template argument 'number', constant expression expected.
If I replace template <int c> by template <int c, int d> and use it accordignly, it works fine. But I want d to be the same value as b.
My questions:
Why the example doesn't work?
How can I enforce d to be the same than b?
Thanks.