1

i dont understand some things in a code from a tutorial
first one: what is that comma "," doing in the middle there? is it mb a overloaded operator?

u32 TimeStamp = irrTimer->getTime(), DeltaTime = 0;

next i have a weird constructor from class CharacterDemo, why is there a ":" following some variables with weird brackets? im guesseing they are beeing initialized with the value in the brackets.. ?

CharacterDemo::CharacterDemo()
:
m_indexVertexArrays(0),
m_vertices(0),
m_cameraHeight(4.f),
m_minCameraDistance(3.f),
m_maxCameraDistance(10.f)
{
    m_character = 0;
    m_cameraPosition = btVector3(30,30,30);
}

im rly curiouse, explanation much appriciated

alfalfa
  • 147
  • 1
  • 8
  • Hint: `u32` is a type. Also, http://stackoverflow.com/questions/1711990/what-is-this-weird-colon-member-syntax-in-the-constructor – chris Nov 16 '12 at 00:31

2 Answers2

4

It's an initialization list.

It calls the constructors of the members and parent classes of the specified class.

Note that you can only use it in the constructor of a class (because it only happens at its construction).

[edit] For your first question, it's a way to declare multiple variables of the same type at once. Note that it will not always work as expected : int * a, b will declare a variable a of type int *, and another variable b of type int (not a pointer).

Maël Nison
  • 7,055
  • 7
  • 46
  • 77
  • +1 for mentioning the reason why this should be avoided in general, because too many people will not care to check up the details on how it works and quickly get confused. – Tamara Wijsman Nov 16 '12 at 00:37
2

what is that comma "," doing in the middle there?

A statement like int i = 3, j = 4; is the same as int i = 3; int j = 4;

So, u32 TimeStamp = irrTimer->getTime(), DeltaTime = 0; is defining and initializing two variables of type u32: one named TimeStamp and the other named DeltaTime.

why is there a ":" following some variables with weird brackets? im guesseing they are being initialized with the value in the brackets.. ?

That's correct: google for c++ member initialization list.

ChrisW
  • 54,973
  • 13
  • 116
  • 224