Try this:
Code:
#include<iostream>
using namespace std;
template<int ivar = 5>
class MyClass
{
public:
static double stvar;
};
template<int ivar>
double MyClass<ivar>::stvar = .5;
int main()
{
cout<<MyClass<30>.stvar<<endl;
cout<<MyClass<60>.stvar<<endl;
return 0;
}
I don't know too much about templates, but from what I can gather it's generally not a good idea to use non-type parameters because they are restrictive, and templating a class with only a non-type parameter doesn't seem like a very good idea.
I think you can accomplish what you want doing this:
Code:
#include<iostream>
using namespace std;
template<typename T>
class MyClass
{
public:
static double stvar;
//some stuff with type T
};
template<typename T>
double MyClass<T>::stvar = .5;
int main()
{
cout<<MyClass<int>.stvar<<endl;
cout<<MyClass<double>.stvar<<endl;
return 0;
}