[Dcmlib] GDCM_UNFOUND et static object initialization

Mathieu Malaterre mathieu.malaterre at kitware.com
Sun Jan 9 01:59:17 CET 2005


Yo,

  Je me suis fais tirer les oreilles sur la mailing liste de gcc, a cause du :

   static const std::string GDCM_UNFOUND = "foo";

   Apparement c'est une erreur de debutant...

   Plusieurs solution:
1. Celle que j'ai faite, qui ressemble *enormement* a un hack de quelqu'un qui n'a rien compris au probleme.

2. Celle proposer par Gabriel Dos Reis sur la ML de gcc:

---------------------------
I regard objects defined in header files almost always as bad ideas to
begin with.  Notable exceptions are manifest constants.  Why don't you
move that foo to an implementation file and encapsulate it in a function?

    // header.H
    const std::string& foo();

    // implementation.C
    const std::string& foo() {
        static const std::string instance = "foo";
        return instance;
    }

see the abundant literature.
----------------------------------


Si ca gene personne je prefererais passer a la deuxieme solution qui semble plus generale...

Mathieu





More information about the Dcmlib mailing list