A new syntax (to me)

D

Duane Evenson

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})$");
}
 
M

Michiel.Salters

Duane said:
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
 
M

mlimber

Duane said:
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
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top