A new syntax (to me)

Discussion in 'C++' started by Duane Evenson, Apr 21, 2006.

  1. What does the line :
    m_stationDb(stationDB), m_units(units), m_date(date), m_time(time),
    m_localUTCOffse(localUTCOffset)
    in kweather metarparser.cpp constructor (shown below) mean?
    I don't really know C++ and can't find reference to this in my C++ books.
    TIA


    MetarParser::MetarParser(StationDatabase *stationDB,
    KLocale::MeasureSystem units,
    QDate date,
    QTime time,
    unsigned int localUTCOffset) :
    m_stationDb(stationDB), m_units(units), m_date(date), m_time(time), m_localUTCOffset(localUTCOffset)
    {
    CoverRegExp = QRegExp("^(FEW|SCT|BKN|OVC|SKC|CLR|CAVOK)([0-9]{3})?(?:TCU|CB)?$");
    CurrentRegExp = QRegExp("^(\\+|-|VC)?([A-Z]{2,4})$");
    WindRegExp = QRegExp("^([0-9]{3}|VRB)([0-9]{2,3})(?:G([0-9]{2,3}))?(KT|KMH|MPS)$");
    VisRegExp = QRegExp("^([0-9]{1,2})SM$");
    VisFracRegExp = QRegExp("^1/(2|4)SM$");
    TempRegExp = QRegExp("^(M)?([0-9]{2})/(?:(M)?([0-9]{2}))?$");
    TimeRegExp = QRegExp("^([0-9]{2}:[0-9]{2})$");
    DateRegExp = QRegExp("^([0-9]{4}/[0-9]{2}/[0-9]{2})$");
    PressRegExp = QRegExp("^([AQ])([0-9]{4})$");
    TempTenRegExp = QRegExp("^T([01][0-9]{3})([01][0-9]{3})$");
    }
     
    Duane Evenson, Apr 21, 2006
    #1
    1. Advertising

  2. Duane Evenson

    Guest

    Duane Evenson wrote:
    > What does the line :
    > m_stationDb(stationDB), m_units(units), m_date(date), m_time(time),
    > m_localUTCOffse(localUTCOffset)
    > in kweather metarparser.cpp constructor (shown below) mean?
    > I don't really know C++ and can't find reference to this in my C++ books.
    >
    > MetarParser::MetarParser(StationDatabase *stationDB,
    > KLocale::MeasureSystem units,
    > QDate date,
    > QTime time,
    > unsigned int localUTCOffset) :
    > m_stationDb(stationDB), m_units(units), m_date(date), m_time(time), m_localUTCOffset(localUTCOffset)
    > {


    It's the constructor initializer list. The m_ identifiers are probably
    members (the
    same syntax is used to initialize base classes, but the m_ suffix is
    often
    used to distinguish members from base classes).

    The advantage of it is that members initialized that way are directly
    initialized
    with the correct value, and need not have default constructors. Any
    member
    NOT listed there is default-initialized (which for 'int' means not at
    all). You then
    have to assign a value in the body of the ctor. Default construction
    followed
    by assignment might be more expensive.

    HTH,
    Michiel Salters
     
    , Apr 21, 2006
    #2
    1. Advertising

  3. Duane Evenson

    mlimber Guest

    Duane Evenson wrote:
    > What does the line :
    > m_stationDb(stationDB), m_units(units), m_date(date), m_time(time),
    > m_localUTCOffse(localUTCOffset)
    > in kweather metarparser.cpp constructor (shown below) mean?
    > I don't really know C++ and can't find reference to this in my C++ books.
    > TIA
    >
    >
    > MetarParser::MetarParser(StationDatabase *stationDB,
    > KLocale::MeasureSystem units,
    > QDate date,
    > QTime time,
    > unsigned int localUTCOffset) :
    > m_stationDb(stationDB), m_units(units), m_date(date), m_time(time), m_localUTCOffset(localUTCOffset)
    > {
    > CoverRegExp = QRegExp("^(FEW|SCT|BKN|OVC|SKC|CLR|CAVOK)([0-9]{3})?(?:TCU|CB)?$");
    > CurrentRegExp = QRegExp("^(\\+|-|VC)?([A-Z]{2,4})$");
    > WindRegExp = QRegExp("^([0-9]{3}|VRB)([0-9]{2,3})(?:G([0-9]{2,3}))?(KT|KMH|MPS)$");
    > VisRegExp = QRegExp("^([0-9]{1,2})SM$");
    > VisFracRegExp = QRegExp("^1/(2|4)SM$");
    > TempRegExp = QRegExp("^(M)?([0-9]{2})/(?:(M)?([0-9]{2}))?$");
    > TimeRegExp = QRegExp("^([0-9]{2}:[0-9]{2})$");
    > DateRegExp = QRegExp("^([0-9]{4}/[0-9]{2}/[0-9]{2})$");
    > PressRegExp = QRegExp("^([AQ])([0-9]{4})$");
    > TempTenRegExp = QRegExp("^T([01][0-9]{3})([01][0-9]{3})$");
    > }


    As Mr. Salters indicated, it's an initializer list. Compare this FAQ:

    http://www.parashift.com/c -faq-lite/ctors.html#faq-10.6

    Cheers! --M
     
    mlimber, Apr 21, 2006
    #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. gabriele renzi
    Replies:
    2
    Views:
    238
    gabriele renzi
    Dec 31, 2005
  2. Ken Bloom
    Replies:
    3
    Views:
    242
  3. Good Night Moon
    Replies:
    9
    Views:
    315
    Rick DeNatale
    Jul 25, 2007
  4. Jacob Grover
    Replies:
    5
    Views:
    351
    Jacob Grover
    Jul 18, 2008
  5. Replies:
    2
    Views:
    509
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page