Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2007-11-07 18:29:36


on Wed Nov 07 2007, Steven Watanabe <steven-AT-providere-consulting.com> wrote:

> AMDG
>
> Michael Marcin <mmarcin <at> method-solutions.com> writes:
>
>>
>> namespace boost
>> {
>> namespace ptr_container_detail
>> {
>> const char* const count = "count";
>> const char* const item = "item";
>> const char* const first = "first";
>> const char* const second = "second";
>> }
>> }
>>
>
> Alas, that only replace one form of ODR violation
> with more subtle one.
>
> static const char* count = "count";
>
> void foo(const char*);
> inline void bar() {
> // ODR violation here. count refers to
> // different objects in different translation
> // units. (See section 3.2/5 of the standard.)
> foo(count);
> }

  template <int = 0>
  struct count
  {
      static char const* const s;
  };

  template <int n>
  char const* const count<n>::s = "count";

  inline void bar()
  {
      foo(count<>::s);
  }

HTH,

-- 
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