|
Boost : |
From: Jeff Garland (jeff_at_[hidden])
Date: 2007-11-07 07:30:30
Felipe Magno de Almeida wrote:
> On 11/7/07, Thorsten Ottosen <thorsten.ottosen_at_[hidden]> wrote:
>> Felipe Magno de Almeida skrev:
>>> This gives multiple definition errors when #include'd by more than one
>>> translation unit.
>>>
>>> namespace boost
>>> {
>>> namespace ptr_container_detail
>>> {
>>> const char* count = "count";
>>> const char* item = "item";
>>> const char* first = "first";
>>> const char* second = "second";
>>> }
>>> }
>> Thanks. Is there an easy way to fix it?
>
> I couldn't think of anything that wouldn't cause ODR violation.
>
It's a bit ugly, but you can use templates. There's an example in
boost/date_time/time_facet.hpp, but it goes something like this:
template <class CharT>
struct ptr_container_stuff {
public:
typedef CharT char_type;
static const char_type count[6];
static const char_type item[5];
...
};
template <class CharT>
const typename ptr_container_stuff<CharT>::char_type
ptr_container_stuff<CharT>::count[6] = {'f','i','r','s','t'};
template <class CharT>
const typename ptr_container_stuff<CharT>::char_type
ptr_container_stuff<CharT>::item[5] = {'i','t','e','m'};
Jeff
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk