public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* dynamic library and initialisation
@ 2004-09-06 11:49 sebpilate
  2004-09-07 13:02 ` Eljay Love-Jensen
  0 siblings, 1 reply; 2+ messages in thread
From: sebpilate @ 2004-09-06 11:49 UTC (permalink / raw)
  To: gcc-help

Hi,

i have the folowing problem :

i have a dynamic library and some object in this library are never initialized.
Theses objects a static member of a class.
I m looking for a way to initialized theses objects.

Thanks.

-- 
Sebastien

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: dynamic library and initialisation
  2004-09-06 11:49 dynamic library and initialisation sebpilate
@ 2004-09-07 13:02 ` Eljay Love-Jensen
  0 siblings, 0 replies; 2+ messages in thread
From: Eljay Love-Jensen @ 2004-09-07 13:02 UTC (permalink / raw)
  To: sebpilate, gcc-help

Hi Sebastien,

Use an class method accessor to guarantee initialization.

class NoGood
{
public:
    static Thingy thing;
};
// Hey, not always initialized!
Thingy NoGood::thing("alpha", "beta");

- - - - -

class ThisWorks
{
public:
   static Thingy& GetThingy();
};
Thingy& ThisWorks::GetThingy()
{
   static Thingy thing("alpha", "beta");
   return thing;
}

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-09-07 13:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-06 11:49 dynamic library and initialisation sebpilate
2004-09-07 13:02 ` Eljay Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).