Boost logo

Boost :

From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2004-05-05 12:16:10


"David Abrahams" <dave_at_[hidden]> wrote

> "Arkadiy Vertleyb" <vertleyb_at_[hidden]> writes:
> > I could, but I use anonimous namespaces to avoid this. This ensures
every
> > compilation unit has it's own set of encoding/decoding classes, and
takes
> > care of ODR.
>
> I'm afraid it doesn't, technically, if typeof is used within a
> template that's seen in multiple translation units. That said, I'm
> willing to accept it if it really works.

In my understanding, the problem goes like this:

in one translation unit (after preprocessing is done):

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?

Regards,
Arkadiy


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