2013-04-08 122 views
-3

我在写下面的重载构造函数时遇到了困难。这就是我被要求做的事情。为需要三个点作为输入的Plane类创建一个重载的构造函数。将这些输入命名为pointU,pointV和pointW。C#重载的构造函数

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

namespace Geometry 
{ 
    public class Plane 
    { 
     //--------------------------------------------------------------------- 
     //           PRIVATE INSTANCE VARIABLES 
     private Point u; 
     private Point v; 
     private Point w; 

     //--------------------------------------------------------------------- 
     //               CONSTRUCTORS 
     public Plane() 
     { 
      u = new Point(); 
      v = new Point(); 
      w = new Point(); 
     } 

     //Overloaded Constructor with 3 Points as inputs 
+0

@AMR是的功课,但它的一个非常小的块到一类,我甚至不需要了... – 2013-04-08 01:01:14

回答

2

重载意味着更改您的构造函数的签名,而不是在默认ctor中有三个实例。 所以

public Plane() 
    { 
    u=new Point(); v= new Point() ; w=new Point() 
    } 

应该是:

public Plane(Point p1, Point p2, Point p3) 
{ 
    u= p1; v = p2; w=p3; 
} 
+0

什么是应该指的是第一部分?这听起来像是你引用了这个问题,但是那里没有那样的东西。 – svick 2013-04-08 00:52:29

+0

@svick是的,它修复它。 – 2013-04-08 00:53:31

0

要使用3点overlaod的constuctor你只需要3个参数添加到构造函数签名

例子:

public Plane(Point pointU, Point pointV, Point pointW) 
{ 
    u = pointU; 
    v = pointV; 
    w = pointW; 
} 
2

这是一个重载的构造函数,接受你的3分和assig把他们交给你的班级成员。

public Plane(Point u, Point v, Point w){ 

       this.u = u; 
       this.v = v; 
       this.w = w;    
}