I was playing around with static classes to do some initialization before the program starts when I found out that this won't link:
static struct Outer
{
static struct Inner
{
int m_inner;
Inner()
{
m_inner = 0xc0de;
}
} InnerInstance;
int m_outer;
Outer()
{
m_outer = 0xbeef;
}
} OuterInstance;
int main()
{
printf("%d\n%d\n", OuterInstance.m_outer,
OuterInstance.InnerInstance.m_inner);
}
It gives me this:
main.obj : error LNK2001: unresolved external symbol "public: static struct Outer::Inner Outer::InnerInstance" (?InnerInstance@Outer@@2UInner@1@A)
Can anyone explain what is going on here? It looks correct to me, and it compiles, so what could the problem be? I'm using VC++ 7.1.