By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,797 Members | 1,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,797 IT Pros & Developers. It's quick & easy.

Is it legal to call functions in the initializer list?

P: n/a
Hi,

I often do things like this:

class A
{
....
};

A::A()
: some_member( foo() ), // init some_member with return value of foo()
some_other_member( bar() ) // same
{}

Is this considered bad style or even illegal? I found it to be very handy.

--
Regards,
Matthias
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Matthias wrote:

Hi,

I often do things like this:

class A
{
...
};

A::A()
: some_member( foo() ), // init some_member with return value of foo()
some_other_member( bar() ) // same
{}

Is this considered bad style or even illegal? I found it to be very handy.


It is legal.

Bad style is in the eye of the beholder. I wouldn't consider it bad.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #2

P: n/a
Here is a code that created some problems for me. I solved it by changing
the way it was initialized.
See the commented lines. Debug build was OK. Release build created problems
sometimes.
Sometimes it was OK. It took me sometime to find out what was the problem.

struct SCtxSetList {
SCtxSet<SCtxx>** __ppm0;
uint __nx : 9;
uint __nxIncrement : 5;
SCtxSetList()
:
//__nxIncrement(2), //Detected an optimization problem here
__nxIncrement(0),//fix
//__ppm0(new SCtxSet<SCtxx>* [1 << __nxIncrement]), //Detected an
optimization problem here
__ppm0(new SCtxSet<SCtxx>* [1]), //fix
__nx(0)
{
uint nxIncrement = 1 << __nxIncrement;
memset(__ppm0, 0, nxIncrement * sizeof(SCtxSet<SCtxx>*));
}
....

"Karl Heinz Buchegger" <kb******@gascad.at>, haber iletisinde sunlari
yazdi:41***************@gascad.at...
Matthias wrote:

Hi,

I often do things like this:

class A
{
...
};

A::A()
: some_member( foo() ), // init some_member with return value of foo() some_other_member( bar() ) // same
{}

Is this considered bad style or even illegal? I found it to be very handy.


It is legal.

Bad style is in the eye of the beholder. I wouldn't consider it bad.

--
Karl Heinz Buchegger
kb******@gascad.at

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.