3 / 3 / 0
Регистрация: 14.09.2012
Сообщений: 84
1

В чем ошибка?

24.11.2012, 17:31. Показов 747. Ответов 2
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Есть вот такие классы:

C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class AbstractGraphicsFigure : public QGraphicsItem
{
public:
    AbstractGraphicsFigure();
    inline void setType(FigureType TYPE) { type = TYPE; }
    inline FigureType getType() { return type; }
    inline QRectF boundingRect() const { return bounding_rect; }
    inline QRectF getBoundingRect() { return bounding_rect; }
    inline void setBoundingRect (QRectF rect) { bounding_rect = rect; }
 
    virtual FigureType figureType() = 0;
    virtual void updateModel() = 0; //name = updateModel();
    virtual bool Move(QPoint point) = 0;
    virtual bool Crossing() = 0;
    virtual void Scale(float f);
 
    inline void setModel(Figure *Model) { model = Model; updateModel(); update(bounding_rect); }
    inline Figure *getModel() { return model; }
 
private:
    FigureType type;
    Figure *model;
    QRectF bounding_rect;
};

C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Figure
{
public:
    Figure ();
    ~Figure ();
 
    inline QPoint Center() { return center; }
    inline void setCenter(QPoint c) { center = c; }
    inline void Add (Figure *figure) { childrens->push_front(figure); }
    inline QList<Figure*> *Contain() { return childrens; }
    inline void setParent(Figure *Parent) { parent = Parent; }
    inline Figure *getParent() { return parent; }
 
    virtual void Scale(float f) = 0;
 
 
private:
    QPoint center;
    Figure *parent;
    QList<Figure*> *childrens;
};
C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Triangle : public Figure
{
public:
    Triangle();
    Triangle(float rad, QPoint c);
    inline QPoint Top() { return top; }
    inline QPoint BottomLeft() { return bottom_left; }
    inline QPoint BottomRight() { return bottom_right; }
    inline float Radius() { return radius; }
    void Set (float rad, QPoint c);
 
    void Scale(float f);
 
private:
    float radius;
    QPoint top;
    QPoint bottom_left;
    QPoint bottom_right;
};
C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class TriangleItem : public AbstractGraphicsFigure
{
public:
    TriangleItem(Triangle *Model);
 
    void updateModel();
    bool Move(QPoint point) {return true;}
    bool Crossing() {return true;}
 
    FigureType figureType() { return TRIANGLE; }
    QPainterPath shape() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    
 
private:
 
};
Определяю метод QPainterPath TriangleItem::shape() const:
C++ (Qt)
1
2
3
4
5
6
7
8
9
QPainterPath TriangleItem::shape() const
{
    Triangle *model = static_cast<Triangle*>(getModel());
    QPainterPath path;
    QPolygon polygon;
    polygon << model->Top() << model->BottomLeft() << model->BottomRight();
    path.addPolygon(polygon);
    return path;
}
и на этом моменте ошибка:
C++ (Qt)
1
Triangle *model = static_cast<Triangle*>(getModel());
Собственно что пишет:
\..\Figures\TriangleItem.cpp:21: ошибка: passing 'const TriangleItem' as 'this' argument of 'Figure* AbstractGraphicsFigure::getModel()' discards qualifiers

В чем может быть трабла?
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
24.11.2012, 17:31
Ответы с готовыми решениями:

Ошибка method range of object global failed в чем ошибка
Sub ПроверкаВвода() Dim A As Range Dim B As Range ...

Ошибка -is not a valid integer value (не является допустимым целым значением), не понимаю в чем ошибка
//--------------------------------------------------------------------------- #include &lt;vcl.h&gt;...

Выскакивает ошибка Stack around the voriable 'text' was corrupted. Подскажите пожалуйста в чём ошибка
Выскакивает ошибка Stack around the voriable 'text' was corrupted. Подскажите пожалуйста в чём...

Ошибка при передаче параметров в функцию. Объясните, ребят, пожалуйста, в чем ошибка
Есть функция, которую необходимо отобразить в виде линий уровня. Далее с помощью простого...

2
Псевдослучайный
1946 / 1145 / 98
Регистрация: 13.09.2011
Сообщений: 3,215
24.11.2012, 17:36 2
Добавь getModel() спецификатор const, нельзя вызывать неконстантные методы из константных.
1
3 / 3 / 0
Регистрация: 14.09.2012
Сообщений: 84
24.11.2012, 17:53  [ТС] 3
Цитата Сообщение от NoMasters Посмотреть сообщение
Добавь getModel() спецификатор const
Спасибо за помощь, то что доктор прописал.
0
24.11.2012, 17:53
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
24.11.2012, 17:53
Помогаю со студенческими работами здесь

В чем ошибка?По одной строке нормально в базу заходят,а две сразу вылетает ошибка?
INSERT INTO `jos_menu` (`id`, `menutype`, `name`, `alias`, `link`, `type`, `published`, `parent`,...

Реализовать через тип данных структура. При сборке и отладки возникает ошибка. В чем ошибка?
С++ в таблице из 5 строк хранятся данные о товарах: наименование, цена, количество. Определить и...

Ошибка 2 error LNK2019, не пойму в чем ошибка
Выдает такую ошибку: Ошибка 2 error LNK2019: ссылка на неразрешенный внешний символ &quot;int __cdecl...

В чем ошибка? При запуске программы открывается консоль и сразу ошибка о завершении программы
К тому же выдает warning: deprecated conversion from string constant to 'char*' . #include...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
3
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru