Конструкторы класса, наследование - C#
Формулировка задачи:
Доброго времени суток!
Создал класс и несколько производных от него. В некоторых классах (circle, rectangle) появилась необходимость объявить не один, а два конструктора с разными параметрами, и вот с ними возникла проблема - выдаёт ошибку (класс rectangle, конструктор public rectangle (point x, double w, double h)). Не пойму почему, объясните пожалуйста.
А ещё в функциях "mov" пишет предупреждение "скрывает наследуемый член". То же не понимаю что это значит и как это устранить. Объясните пожалуйста.
abstract class obgekt
{
public obgekt()
{ }
abstract public double S();
}
class point
{
double x, y;
public point (double x, double y)
{
this.x = x;
this.y = y;
}
public point mov(double a, double b)
{
double x2, y2;
x2 = x + a;
y2 = y + b;
return new point (x2,y2);
}
public double X
{
get { return x; }
}
public double Y
{
get { return y; }
}
}
class circle:point
{
point c;
double r;
public circle (double x, double y,double r):base(x,y)
{
this.r = r;
c=new point(x,y);
}
public circle(point o, double r)
{
this.r = r;
c =o;
}
public circle mov(double a, double b)
{
point c1= c.mov(a, b); //вызывает метод из класса к кот относится объект
return new circle (c1, r);
}
public circle mov_simetriy(double x3, double y3)
{
//написать в point здесь вызвать для центра
point c1 = c.mov(x3, y3);
return new circle(c1, r);
}
public double S()
{
double S;
return S = 3.14*r*r;
}
public point C
{
get { return c; }
}
}
class rectangle: point
{
point left_ugol;
double w, h;
public rectangle (double x, double y, double w, double h):base(x,y)
{
// для lvu вызываем конструктор point
left_ugol = new point(x, y);
this.w = w;
this.h = h;
}
public rectangle (point x, double w, double h)
{
// для lvu вызываем конструктор point
left_ugol =x;
this.w = w;
this.h = h;
}
public point ugol
{
get { return left_ugol; }
}
public rectangle mov(double a, double b)
{
point left_ugol2 = left_ugol.mov(a, b);
return new rectangle (left_ugol2, w, h);
}
public double S()
{
double S;
return S = w * h;
}
}
class square:rectangle
{
public square(double x1, double y1, double w):base(x1,y1,w,w)
{
}
public double S()
{
return base.S();
}
public square mov (double x1, double y1)
{
base.mov(x1,y1);
return new square (x1,y1,w);
}
}Решение задачи: «Конструкторы класса, наследование»
textual
Листинг программы
public rectangle(point x, double w, double h) : base(x.X, x.Y)
{
// для lvu вызываем конструктор point
left_ugol = x;
this.w = w;
this.h = h;
}