Boost logo

Boost :

From: Andrey Semashev (andysem_at_[hidden])
Date: 2007-04-03 15:06:29

Hello Martin,

Tuesday, April 3, 2007, 8:07:38 PM, you wrote:


>> Although I liked this at first too, it seems to me it cannot be
>> always implemented. I was now trying to add a singleton to my
>> library and I can't do it with headers alone. I need to maintain
>> the pointer to the global instance somewhere, and that means having a
>> global variable which cannot be defined in a header (or otherwise
>> you'll get duplicates). Unless I'm missing something, that is...

> Static variable in an inline function.

Or a static member of a template class, which is instantiated with
only one template parameters set.

But, as Jeff Garland noted, this is only suitable if your header is
used only in one module. Otherwise the singleton should be extracted
to a separate module (.dll or .so). Though this is not necessary on

Best regards,
 Andrey                            mailto:andysem_at_[hidden]

Boost list run by bdawes at, gregod at, cpdaniel at, john at