I was playing around with class templates and statics and saw this:
template<int I>
struct rat
{
static bool k;
};
bool rat<3>::k = 0; //this is line 84 of the only source file play.cpp
int main(int argc, char **argv)
{
rat<3> r;
}
compiler error:
play.cpp:84: error: too few template-parameter-lists
I thought when I said rat<3>::k i was instantiating that template and defining the static for that particular template and thus the use of rat<3> would be fine from there on..how come this isn’t working?
should be
but better use
falseforboolthen0since it’s more readableAlso in case you want to make you variable initialized for all templates as
truefor example:And you can still specialize template for
I = 3: