This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ordering of constructors


> Why not put a function call in the constructor for A that make sure B
> initialized?

A simpler technique is to wrap the static members into functions 
returning the static member ie:

struct A {

    typedef whatever B;

    static B& get_member() {
         static B static_member;
         return B;
    }
};

This has solved the problem of static member ordering for me once 
for all. I just wonder why this approach is not used transparently 
by the compiler for all static members.... Maybe there is some hidden 
cost I do not see... Presumably, the implementation of function static 
members requires a boolean per member... Never went to see how this 
is done.

--------------------------------------------------------------------
Theodore Papadopoulo
Email: Theodore.Papadopoulo@sophia.inria.fr Tel: (33) 04 92 38 76 01
 --------------------------------------------------------------------



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]