I came across a compile.. oddity? recently that led me to believe that a template, when created, is created in the same namespaces (or, at least, using
the same namespaces) as where is was declared. That is;
template<class T>
class bar
{
public:
static int stuff(){return T::stuff();}
};
namespace ONE
{
struct foo
{
static int stuff(){return 1;}
};
}
namespace TWO
{
struct foo
{
static int stuff(){return 2;}
};
}
using namespace TWO;
int main()
{
return bar<foo>::stuff();
}
will return 1 when using namespace ONE
and 2 when using namespace TWO
.
Why? And are there other "odd" or "unexpected" interactions between namespaces and templates?
Edit: This was confusing at the time because the same templates were being used across multiple files, each using
a different namespace.