Can I use an instance variable as an argument in an initialiser list as
follows:
class bar
{
private:
int i1_;
public:
bar(int i1):i1_(i1){}
};
class fooBase
{
private:
bar& ref_my_bar_;
public:
fooBase(bar& ref_my_bar):ref_my_bar_(ref_my_bar){}
virtual ~fooBase(void){}
};
class fooDerived:public fooBase
{
private:
bar my_bar_;
public:
fooDerived(void):fooBase(my_bar_),my_bar_(42){} // ???
virtual ~fooDerived(void){}
};
This compiles OK, and intuitively I'd have thought it was safe whether
fooBase(my_bar_) or my_bar_(42) gets executed first. I'm simply passing
a reference down to a base class, and whether my_bar_'s constructor
gets called before or after this should make no odds.
Does the standard mandate any particular order of execution for this
combination?
Is what I'm doing safe in general, or are there times when this
approach won't do what I'd expect?
--
Simon Elliott http://www.ctsn.co.uk