Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-05-07 12:24:26


"Arkadiy Vertleyb" <vertleyb_at_[hidden]> writes:

> template<class T> struct encode<std::vector<T> >
> {
> typedef ... // use some integral constant to encode the vector
> };
>
> in another translation unit:
>
> template<class T> struct encode<std::vector<T> >
> {
> typedef ... // use another integral constant to encode the vector
> };
>
> Technically speaking, this is one class with different bodies, and can
> represent a problem with ODR (at linking? But isn't the linker concerned
> only with functions? The only functions here are those generated
> automatically, and never used, but they are similar in all respects. The
> actual difference is in typedefs).
>
> Having said this, I still think the anonimous namespace will take care of
> this by creating totaly distinct classes in different compilation units.
> Why not? Can you ellaborate?

Any time a template is instantitated, all names in its definition must
map to the same entities in each translation unit, or you violate the
ODR. By definition, names in the unnamed namespace refer to distinct
entities in each translation unit.

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk