Hicham Mouline wrote:
Quote:
hi,
>
I have a template function <typename cT, typename tT, int n>
{
....
double array[n];
>
if (n==2)
binomial code
else if (n==3)
trinomial code (array[0] array[1] array[2])
else
....
You should overload the function for different values of n instead of using
an if statement to distinguish the cases. Alternatively, you can isolate
that piece of code into another function and overload that. Something like:
template < int n, typename cT, typename tT >
void polynomial_code ( ct & c, tT & t );
template < typename cT, typename tT>
void polynomial_code<2,cT,tT( ct & c, tT & t ) {
binomial code
}
template < typename cT, typename tT>
void polynomial_code<3,cT,tT( ct & c, tT & t ) {
trinomial code
}
template <typename cT, typename tT, int n>
...
polynomial_code<n>( ct_arg, tt_arg );
...
Maybe, I got the syntax slightly wrong, but I hope the idea is clear.
[snip]
Best
Kai-Uwe Bux