views:

132

answers:

4

Hi, I'm just getting the concept of chaining constructors down, but I can't figure out how to chain these two particular constructors together, so I would appreciate it if somebody could help me out.

Thanks!

Constructors

// default constructor
// purpose: initialize data members to zero
// Parameters: none
// returns: none
public Line()
{
    startPoint.xCoord = 0;
    startPoint.yCoord = 0;
    endPoint.xCoord = 0;
    endPoint.yCoord = 0;
}


// parameterized constructor
// purpose: initialize data members to p1 and p2
// Parameters: Point objects p1 and p2
// returns: none
public Line(Point p1, Point p2)
{
    startPoint = p1;
    endPoint = p2;
}
+3  A: 

There's really no win in chaining these.

Stu
+11  A: 
public Line() : this(new Point(), new Point())
{
}
Pavel Minaev
+3  A: 

Try the following

public Line() : this(new Point(0,0), new Point(0,0))
{
}
JaredPar
A: 

This will work for you

// default constructor
// purpose: initialize data members to zero
// Parameters: none
// returns: none
public Line() : this (new Point(0, 0), new Point(0, 0))
{

}
Bob