Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Strange constructor..

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I ran across this constructor, but I don''t understand how it works. Can someone enlighten me?
class MD2
		MD2_MODELVERTEX vertList[100];

		int numGlCommands;
		long* glCommands;

		int numTriangles;

		int stateStart;
		int stateEnd;

		int frameSize;
		int numFrames;
		char* frames;

		int currentFrame;
		int nextFrame;
		int endFrame;
		float interpolation;
	MD2() : stateStart(IDLE1_START), stateEnd(IDLE1_END),
			numGlCommands(0), frameSize(0), numFrames(0), 
			currentFrame(IDLE1_START), nextFrame(currentFrame+1),
			endFrame(IDLE1_END), interpolation(0.0f)
	{	}

What exactly is the '':'' doing? I''ve used it when calling parent constructs..but here it''s calling some variables in some strange way..I''m confused..
/* Everything IMHO */ -Luctus

Share this post

Link to post
Share on other sites
Its initializing variables.
This bit here: MD2() : stateStart(IDLE1_START), stateEnd(IDLE1_END) means "MD2 constructor. Start by setting stateStart to IDLE1_START, and stateEnd to IDLE1_END".
Most people put this code in the body, but theres some things that have to be initialized in this way, like references (because they need to point to a valid object from construction), and calling the base class constructor.

Share this post

Link to post
Share on other sites
When you construct an object from a class it goes through the members of the class and constructs them. You can give those members their initial values in an initialiser list. This is more efficient than constructing the members with a default constructor and then going through them setting them to the values you really want. Also in some cases it''s necessary (ie when a member variable is of a class type that has no default constructor).

The members are created in the order they are declared in the class declaration not in the order of the initialisation list, so that''s something to watch out for, especially if you''re using one value to initialise another.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!