“Point”方法没有采用“0”个参数的重载 是什么意思?

来源:百度知道 编辑:UC知道 时间:2024/05/17 01:26:58
using System;
using System.Collections.Generic;
using System.Text;
class Point
{
public double x, y;
public Point(double x, double y)
{
this.x = x; // 当this在实例构造函数中使用时,
this.y = y; // 它的值就是对该构造的对象的引用。
}
}

namespace ConsoleApplication1
{
class Test
{
public static void Main()
{
Point a = new Point(); // 出错
Point b = new Point(3, 4); // 用构造函数初始化对象
Console.WriteLine("a.x={0}, a.y={1}", a.x, a.y);
Console.WriteLine("b.x={0}, b.y={1}", b.x, b.y);
}
}

}
执行时出现的 “Point”方法没有采用“0”个参数的重载 是什么意思啊?

class Point {
public:
double xval, yval;
Point(double x = 0.0, double y = 0.0) {
xval = x; yval = y;
}

double x() { return xval; }
double y() { return yval; }

double distance (const Point & P){
double xd = xval - P.xval;
double yd = yval - P.yval;
return sqrt(xd*xd + yd*yd);
}

Point relative (const Point & P){
Point r;
r.xval = xval - P.xval;
r.yval = yval - P.yval;
return r;
}

bool is_above_left(const Point & P){
double xd = xval - P.xval;
double yd = yval - P.yval;
if (xd < 0.0 && yd > 0.0) {return 1==1 ;} else { return 1== 0;};
}

double r(){
return sqrt(xval*xval + yval*yval);
}

double theta(){
double rr;
rr = r();
return asin(yval / rr);
}

void print( ){
printf("%f %f\n",xval,yval);
}
};
------------------