class syntax question

Here's a bit of code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
CvClimateInfo::CvClimateInfo() :
m_iDesertPercentChange(0),
m_iJungleLatitude(0),
m_iHillRange(0),
m_iPeakPercent(0),
m_fSnowLatitudeChange(0.0f),
m_fTundraLatitudeChange(0.0f),
m_fGrassLatitudeChange(0.0f),
m_fDesertBottomLatitudeChange(0.0f),
m_fDesertTopLatitudeChange(0.0f),
m_fIceLatitude(0.0f),
m_fRandIceLatitude(0.0f)
{
}


does this means that these variables are initialized with the values between parentheses?
Last edited on
Yes, everything after the : is part of the instance member initialization list. It is more efficient than doing operator= assignments in the constructor body in some cases, and it allows you to call other constructors of a member object than the default constructor.

In C++11, you can have default values specified with the member declarations rather than copypasting code between constructors:
1
2
3
4
class MyClass
{
    int member_var {7};
};


Also, use [] and not <> for the code tags.
Last edited on
alright thanks a lot!!
Topic archived. No new replies allowed.