Re: can't specialize a template
Arkadiy wrote:
I have a template defined in unnamed namespace (let's say in h1.h) and
I specialize it in a different header (h2.h).
Why? Typically, anonymous namespaces are used to separate code from all
other code that could possibly conflict with it. Headers are used to
declare common code that can be used universally. Those two concepts don't
match.
Now, if h1.h is included in the precompiled header, and h2.h isn't,
VC8.0 express can't compile such code. It kind of (*) works in VC7.1,
and I am pretty sure it worked in VC8.0 beta.
Every translation unit that includes an anonymous namespace gets its
own 'instance' thereof. IIRC the problem with precompiled headers is that
they are generated as part of the associated translation unit, but when
included in other translation units anonymous namespaces are not handled
correctly, i.e. to the compiler it seems like two distinct 'instances' of
the anonymous namespace which are intended to not conflict, but in your
case they are impossible to make interoperable.
Can anybody provide any insights on this subject?
a) Don't do it.
b) If you need to do it, don't use precompiled headers.
c) If you need both, include the headers declaring extensions in the
precompiled header, too.
Uli