is this safe?

D

Damien Cymbal

Sorry, don't have a copy of the standard handy anywhere. Given this:

// header

class Test
{
public:
Test() {}
~Test() {}

private:
static const string strings[];
static const string STR1;
static const string STR2;
};

// impl

const string Test::STR1("String #1");
const string Test::STR2("String #2");

const string Test::strings[] =
{
STR1,
STR2
};

Is the initialization of the static members guaranteed to proceed in
the order in which they are encountered? The 2 compilers I have tried
work fine given the above and have problems if I flip-flop the inits
of the strings and the array, so that was my *assumption*. But is
this safe/portable?

Thanks.

dc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,102
Messages
2,570,646
Members
47,247
Latest member
GabrieleL2

Latest Threads

Top