Как решить неоднозначный базовый класс в переполнении стека

Оба базовых класса, Arc и Lines, являются производными от класса Shape.

Компилятор говорит Ojbect b1 «ошибка: форма неоднозначна». Я знаю, что создаются два экземпляра Shape, но не знаете, как это решить?

Graph_lib::Box b1(Point,100,100), 100,100);
win1.attach(b1);

Этот класс сможет нарисовать прямоугольник с закругленными углами. Я только что написал код для части Box Lines, пока не попал в Arc, так как это даже не сработает.

//------------------------------------------------------------------------------

struct Box : Lines , Arc {

Box(Point xy, int ww, int hh);

void Top_segment();
void Bottom_segment();
void Left_side_segment();
void Right_side_segment();

void draw_lines() const;

int height() const { return h; }
int width() const { return w; }
private:
int h;    // height
int w;    // width

double width_tenth; //10% of the width that will calculate the length to remove from each side to make room for the arcs

};

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
Box::Box(Point xy, int ww, int hh): w(ww), h(hh)
{

width_tenth = (xy.x + w) * 0.10;

if (h<=0 || w<=0) error("Bad box: non-positive side");

}
//------------------------------------------------------------------------------
void Box::Top_segment()
{

double top_seg_begin_w;   //where the line segment will begin after deducting 10% of w;
double top_seg_end_w;     //where the line segment will end after deducting 10% of w;

top_seg_begin_w = xy.x + width_tenth;

top_seg_end_w = (xy.x + w) - width_tenth;

Lines::add(Point(top_seg_begin_w,xy.y),Point(top_seg_end_w,xy.y));
}

//------------------------------------------------------------------------------
void Box::Bottom_segment()
{

double bottom_seg_begin_w;
double bottom_seg_end_w;

bottom_seg_begin_w = xy.x + width_tenth;

bottom_seg_end_w = (xy.x + w) - width_tenth;

double y_bottom = xy.y + h;

Lines::add(Point(bottom_seg_begin_w,y_bottom),Point(bottom_seg_end_w,y_bottom));
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void Box::Left_side_segment()
{
double left_seg_begin_h;
double left_seg_end_h;

left_seg_begin_h = xy.y + width_tenth;

left_seg_end_h = (xy.y + h) - width_tenth;

double x_left = xy.x;

Lines::add(Point(x_left,left_seg_begin_h),Point(x_left,left_seg_end_h));
}

//------------------------------------------------------------------------------
void Box::Right_side_segment()
{
double right_seg_begin_h;
double right_seg_end_h;

right_seg_begin_h = xy.y + width_tenth;

right_seg_end_h = (xy.y + h) - width_tenth;

double x_right = xy.x + w;

Lines::add(Point(x_right,right_seg_begin_h),Point(x_right,right_seg_end_h));
}

//------------------------------------------------------------------------------

-1

Решение

Используйте виртуальное наследование для классов Lines и Arc. Например

class Lines : virtual public Shape
{
//...
};

class  Arc : virtual public Shape
{
//...
};
0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector