D
Dave Rahardja
Hi all,
If a class is declared inside a templated function, e.g.
template <typename> fn()
{
class A {};
static A a;
}
And I instantiate fn with the same typename twice, in two different
compilation units,
----
// a.cpp
void b();
int main()
{
fn<int>();
b();
}
----
// b.cpp
void b()
{
fn<int>(); // identical instantiation
}
Will the static member a be multiply defined at link time? I would think not,
as the two template instantiations have identical instantiation parameters,
and thus should correspond to a single instance. However, MSVC 2005 seems to
think otherwise.
In addition, I would guess that a /different/ instantiation of fn (e.g.
fn<double>()) will yield a /different/ instance of a. Am I right?
-dr
If a class is declared inside a templated function, e.g.
template <typename> fn()
{
class A {};
static A a;
}
And I instantiate fn with the same typename twice, in two different
compilation units,
----
// a.cpp
void b();
int main()
{
fn<int>();
b();
}
----
// b.cpp
void b()
{
fn<int>(); // identical instantiation
}
Will the static member a be multiply defined at link time? I would think not,
as the two template instantiations have identical instantiation parameters,
and thus should correspond to a single instance. However, MSVC 2005 seems to
think otherwise.
In addition, I would guess that a /different/ instantiation of fn (e.g.
fn<double>()) will yield a /different/ instance of a. Am I right?
-dr