Is it legal to call functions in the initializer list?

M

Matthias

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.
 
K

Karl Heinz Buchegger

Matthias said:
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.
 
A

Aslan Kral

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>*));
}
....
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top