Reputation: 147
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
Upvotes: 1
Views: 361
Reputation: 56083
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
.
Upvotes: 2
Reputation: 7353
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).
Upvotes: 4