Why doesn't the below code compile with GCC?
#include <iostream>
template <typename T>
static void fFunc()
{
static T var;
(void)var; // Suppress set-but-not-used warning.
struct g {
static void gFunc()
{
std::cin >> var;
};
};
g::gFunc();
}
int main()
{
fFunc<int>();
}
It fails at link time with:
/tmp/ccYDfCzj.o: In function `gFunc':
tst.cpp:11: undefined reference to `var'
I'm using GCC 4.7.2 on Gentoo Linux (x86-64). It compiles fine with
Clang (3.1) and ICC (13.0.0).
_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
https://lists.gnu.org/mailman/listinfo/help-gplusplus