public XRectangle(Rectangle rect)
        {
            this.rect = rect;
        }public XRound(Point roundCenter, int radius)
        { 
            
        }
XRound继承自XRectangle
为什么我这样写XRound的构造函数总是报错?

解决方案 »

  1.   

    因为你的父类没有参数为0个的构造函数
    子类构造函数其实应该提供父类构造函数的参数
    public XRound(Point roundCenter, int radius):base(new Rectangle())
            { 
                
            }
      

  2.   

    父类初始需要参数
    如果要继承那个父类,可以这样做
    方法一:添加父类的无参构造函数,如public XRectangle(){}
    方法二:
    public XRound(Rectangle rect):base(rect){}
      

  3.   

    基本的知识要先看。
    XRound继承自XRectangle
    你要这样写XRound的构造函数,前提是XRectangle有相同参数的构造函数!public XRound(Point roundCenter, int radius)
            { 
                
            }
      

  4.   

    没有相同的父类的构造函数,当然不行了呀...
    或者用base也可以呀....
      

  5.   

    public XRound(Point roundCenter, int radius):base(new Rectangle())
      { 
       
      }
      

  6.   

     public XRectangle(Rectangle rect)
            {
                this.rect = rect;
            }public XRound(Point roundCenter, int radius):base(new Rectangle())
            { 
                
            }