Hello,
I am having some problems with template metaprogramming in vc++. I am trying to get the following to compile:
#include <iostream>
#include <tchar.h>
#pragma inline_depth(255)
#pragma inline_recursion(on)
using namespace std;
template<double R> struct Sine
{
enum { MaxTerms = 10 };
static inline double sin()
{
return R * Series<R, 0, MaxTerms>::val();
}
};
template <double R, int I, int MaxTerms> struct Series
{
enum
{
Continue = I + 1 != MaxTerms,
NxtI = ( I + 1 ) * Continue,
NxtMaxTerms = MaxTerms * Continue
};
static inline double val()
{
return 1 - R*R/(2.0 * I + 2.0)/(2.0 * I + 3.0)*Series<R*Continue, NxtI, NxtMaxTerms>::val();
};
};
template <> struct Series<0.0, 0, 0>
{
static inline double val() { return 1.0; };
};
#define SineVal( r ) Sine<r>::sin()
int _tmain(int argc, _TCHAR* argv[])
{
char ch;
double val = 5.0;
cout << SineVal(val) << endl;
cin >> ch;
return 0;
}
But i'm getting the following errors:
error C2993: 'double' : illegal type for non-type template parameter 'R'
error C2993: 'double' : illegal type for non-type template parameter 'R'
PS This came straight from Game Programming Gems, and was compiled using visual c++ 2005 express edition.
Thanks for any assistance,
exorcist_bob