View Single Post
  #1 (permalink)  
Old December 5th, 2010, 10:49 AM
pepitagold pepitagold is offline
Registered User
 
Join Date: Jan 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Constructors and keyword " this "

Reading an XNA book , i found this code ( i cut some irrelevant variables ,
the class is " Sprite " )

Code:
int millisecondsPerFrame;
protected Vector2 speed;
const int defaultMillisecondsPerFrame = 16;

public Sprite(Vector2 speed ) :this ( speed ,defaultMillisecondsPerFrame)
{
}

public Sprite(Vector2 speed , int millisecondsPerFrame)
{
    this.speed = speed;
    this.millisecondsPerFrame = millisecondsPerFrame;
}
The Author explains :

The only difference between the two constructors is that the second one requires a
millisecondsPerFrame variable, used to calculate the animation speed. Hence, the
first constructor will just call the second constructor (using the this keyword) and
pass to that constructor all of its parameters, as well as the constant representing the
default animation speed.

I don't understand clearly : is this something like the code explained by Dr.Purdum at page 235 ? ( constructors sloppiness )

Thanks a lot for any explanation