(Initializer list problem....

Hello... I am very new to c++ and I have looked everywhere to try and figure out what this code does. I understand the class arguments and that after the colon is an initializer list. what i don't understand is if m_uSize is set to the value of uSize or how it exactly works. Please help. Thx.

HillTerrain::HillTerrain( unsigned short uSize, float fHillMin,
float fHillMax, unsigned short uNumHills,
unsigned short uFlattening,
bool bIsland, unsigned int uSeed )
: m_uSize( uSize ),
m_fHillMin( fHillMin ),
m_fHillMax( fHillMax ),
m_uNumHills( uNumHills ),
m_uFlattening( uFlattening ),
m_bIsland( bIsland ),
m_uSeed( uSeed )
This is simply a class constructor. You'd create an object of HillTerrain and use this constructor and pass some values to it. The values passed, seen as the parameters, are set into each of the member variables, signified by the m_. An example would be:
HillTerrain myHillTerrain(2, 1.2, 1.5, 5, 0, false, 25)
Your new object, myHillTerrain, would then be initialized with the m_uSize of 2, m_fHillMin of 1.2, etc. It was a new requirement of C++11 that the constructors of classes must initialize all member variables and the colon sets the initializers for the following variables.
It was a new requirement of C++11 that the constructors of classes must initialize all member variables

Do you have any source on this?
Do you have any source on this?


Errr I stand corrected. I forgot I set strict flags on the compiler. That should say that C++11 has allowed non static members to be initialized in constructors, not requiring it.
Topic archived. No new replies allowed.