Is it legal to call functions in the initializer list?

Discussion in 'C++' started by Matthias, Jan 27, 2005.

  1. Matthias

    Matthias Guest

    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
    Matthias, Jan 27, 2005
    #1
    1. Advertising

  2. 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
    Karl Heinz Buchegger, Jan 27, 2005
    #2
    1. Advertising

  3. Matthias

    Aslan Kral Guest

    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" <>, haber iletisinde sunlari
    yazdi:...
    > 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
    >
    Aslan Kral, Jan 27, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Razvan
    Replies:
    7
    Views:
    17,542
    Lee Fesperman
    Jul 4, 2004
  2. Aman
    Replies:
    4
    Views:
    424
    Agent Mulder
    Sep 15, 2003
  3. spipyeah

    initializer list question

    spipyeah, Oct 27, 2003, in forum: C++
    Replies:
    3
    Views:
    307
    spipyeah
    Oct 28, 2003
  4. chriss
    Replies:
    3
    Views:
    457
    chriss
    Sep 10, 2005
  5. Replies:
    20
    Views:
    778
    Alf P. Steinbach
    May 1, 2009
Loading...

Share This Page