Hi guys,

I have an interesting scenario I've tested that really doesn't make any sense to me. First note that I'm using the Visual Studio 2008 compiler.

I have 3 files:

Foo.h
A.cpp
B.cpp

In Foo.h, I have the following:
Code:
class foo
{
    static int s_member;
};

int foo::s_member = 14;
In A.cpp and in B.cpp, I do the following (code is identical in both):

Code:
static int maintest()
{
    foo<0> myfoo;
}
When I compile and link this code, the linker fails saying that two definitions of s_member has been found. This is what I expected. Now let's change the implementations a bit:

Foo.h is now this:

Code:
template< unsigned int t_val >
class foo
{
	static int s_member;
};

template< unsigned int t_val >
int foo<t_val>::s_member = 14;
Both A.cpp and B.cpp have been changed to this:

Code:
static int maintest()
{
    foo<0> myfoo;
}
In the second scenario, the linker does not fail. I would expect it to fail. Since we're instantiating the class with the same template arguments, both files should be referencing the same static member, and thus the same static member should be getting duplicated between translation units *just* like the former scenario. What is happening here? Where is the static *actually* stored?

::EDIT::
Note that A.cpp and B.cpp both include "foo.h", this should have been obvious but I just wanted to mention it.