• 12
• 12
• 9
• 10
• 13

# two simple question at OOP thanks advanced [solved]

This topic is 4191 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

q1 ------------------------------------------------------------------------ public: // Create a default entity CEntity () : Id(0xffffffff), Name("<Unknown>"), AutoMove(false), Instance(NULL), Skeleton(NULL), Particule(NULL), PlayList(NULL), /*CurrentAnim(NoAnim), */NextEmptySlot(0), Source (NULL), Angle(0.0f), AuxiliaryAngle(0.0f), InterpolatedAuxiliaryAngle(0.0f), IsWalking(false), WasWalking(false), IsAiming(false), WasAiming(false), BotState(0) { } --------------------- why at the end of CEntity () had a : ???? and what things is the follow ??? member of CEntity()? what is the : mean? why at the end of all had a {}??? what is that mean?

class CEntity
{
public:

// Create a default entity
CEntity () :
Id(0xffffffff), Name("<Unknown>"), AutoMove(false), Instance(NULL), Skeleton(NULL),
Particule(NULL), PlayList(NULL), /*CurrentAnim(NoAnim), */NextEmptySlot(0), Source (NULL),
Angle(0.0f), AuxiliaryAngle(0.0f), InterpolatedAuxiliaryAngle(0.0f),
IsWalking(false), WasWalking(false), IsAiming(false), WasAiming(false), BotState(0)
{ }

// The id of the entity
uint32							Id;

// The name of the entity
std::string						Name;

// Contain the target position for this entity
NLMISC::CVector					ServerPosition;

// Contain the current position of the entity
NLMISC::CVector					Position;

// The immediate speed of the entity
NLMISC::CVector					ImmediateSpeed;

// The maximum speed of the entity
float							Speed,
// The angle of the entity
Angle,
// Various angle controls for the interpolation
AuxiliaryAngle, InterpolatedAuxiliaryAngle;

// The trajectory (only for snowballs, defined in physics.h)
CTrajectory						Trajectory;

// The state enum of the entity
enum TState	{ Appear, Normal, Disappear };

// The state of this entity
TState							State;
// The date of the beginning of this state
NLMISC::TTime					StateStartTime;

// The type enum of the entity
enum TType	{ Self, Other, Snowball };

// The type of this entity
TType							Type;

// Is it an auto-moving entity
bool							AutoMove;

// The PACS move primitive
NLPACS::UMovePrimitive			*MovePrimitive;
// The collision entity (for ground snapping)
NL3D::UVisualCollisionEntity	*VisualCollisionEntity;
// The mesh instance associated to this entity
NL3D::UInstance					Instance;
// The skeleton binded to the instance
NL3D::USkeleton					Skeleton;
// The particle system (for appear and disappear effects)
NL3D::UInstance					Particule;

// The sound source associated to the entity
NLSOUND::USource				*Source;

void	setState (TState state);

bool							IsWalking;
bool							WasWalking;
bool							IsAiming;
bool							WasAiming;

// Playlist linked to this entity
//	EAnim							CurrentAnim;
uint							NextEmptySlot;
NL3D::UPlayList					*PlayList;
std::queue<EAnim>				AnimQueue;
NL3D::CAnimationTime			StartAnimationTime;

/// \todo remove, just for bot automaton testing
uint							BotState;
NLMISC::TTime					BotStateStart;
};



##### Share on other sites
sorry~ i think i know that~~ it is a constructor~~ sorry i post it so early.

##### Share on other sites
the : means call these constructors for the base class/es and member function
for example :Id(0xffffffff), Name("<Unknown>"), ...... means call the constructor for Id with parameters 0xffffffff and for Name with "<Unknown>" and so on
(note this is only the case when the : is after the constructor of a class)
then the { } is the normal code body for the constructor

hope that helps

##### Share on other sites
: Id(0xffffffff), Name("<Unknown>") etc. is something that is called an initialization list, if it might help ;)

##### Share on other sites
Note that this is a more efficient way than assigning those values in the constructors body. When you do the latter, all member variabeles will first be initialized at their default value, and then get assigned your desired value. With initialization lists, you can immediafly initialize them at that desired value.

For example, the following:

Crate()
{
size = 5;
x = 9;
y = 14;
}

is the same as:

Crate() :
size(0), x(0), y(0)
{
size = 5;
x = 9;
y = 14;
}

and that makes it easy to see why the following is more efficient:

Crate() :
size(5), x(9), y(14)
{
}