Is it possible to return a template?
This is what I’ve been trying, but this isn’t working.
template<int degree>
class Polynomial
{
public:
... ususal stuff ...
// Polynimal<degree - 1>
Polynomial derivative() { /* returns a different template */ }
};
int main()
{
Polynomial<3> cubic;
Polynomial<2> parabola;
parabola = cubic.derivative();
}
Is this possible? What little nugget am I missing?
You can make the member-function a function template:
Or, if you know the degree of the return-polynomial, you can do something like this: