Derek wrote:
> Here is a simple template with a non-const static data member:
>
> template <typename T>
> class Foo
> {
> public:
> static int bar;
> };
>
> template <typename T> int Foo<T>::bar = 42;
>
> What I want to know is how the compiler/linker guarantees there
> will only be one Foo<T>::bar for each possible T? I assume the
> compiler generates storage for Foo<T>::bar in every translation
> unit that instantiates Foo<T> and tasks the linker with stripping
> any duplicates?
Probably. How does the compiler guarantee that there is only one
instance of a member function, for example? The same way, most likely.
If you really want to know the inner workings of a compiler, I'd look
at the source for G++ (it's open source, isn't it?) or asked in
comp.compilers.
V
|