I am wanting to forward declare variable templates in a header file, and then have the actual instantiations in a separate compilation unit.
I was led to believe that C++14 variable templates operated very much like static class variables do. This is unfortunately seeming not to be quite the case, and it is preventing me from forward declaring my variable templates.
template <typename T> struct Variable {
static int variable;
};
template <typename T>
extern int variable;
int main() {
(void) Variable<char>::variable;
// (void) variable<char>; // <-- line 10
}
template <> int Variable<char>::variable = 42;
template <> int variable<char> = 23;
The code sample above compiles and runs as-is under GCC. But uncommenting line 10 gives a compile-time error:
specialization of 'variable<char>' after instantiation
template <> int variable<char> = 23;
^