Strange compiler behaviour (compiler passes wrong argument)
I have following class declaration:
Code:
class GraphicsArc : public GraphicsComponent
{
public:
enum { Type = Arc };
explicit GraphicsArc();
explicit GraphicsArc(const ArcF &arc);
explicit GraphicsArc(qreal cx, qreal cy, qreal radius, qreal startAngle, qreal spanAngle);
~GraphicsArc();
ArcF arc() const;
void setArc(const ArcF &arc);
int type() const { return Type; }
private:
void updateBoundingRect();
ArcF m_arc;
};
and problem is here:
Code:
...
{
QPointF sp1
(endPoint
(m_arc.
center(), m_arc.
radius() - 5,
-m_arc.
startAngle()));
QPointF sp2
(endPoint
(m_arc.
center(), m_arc.
radius() + 5,
-m_arc.
startAngle()));
...
Compiler says:
Quote:
..\TestGraphicView\graphicsarc.cpp: In member function 'virtual QPainterPath GraphicsArc::shape() const':
..\TestGraphicView\graphicsarc.cpp:42: error: passing 'const GraphicsArc' as 'this' argument of 'QPointF GraphicsArc::endPoint(const QPointF&, qreal, qreal)' discards qualifiers
..\TestGraphicView\graphicsarc.cpp:43: error: passing 'const GraphicsArc' as 'this' argument of 'QPointF GraphicsArc::endPoint(const QPointF&, qreal, qreal)' discards qualifiers
I do not understand that, because there also a function updateBoundingRect, which also use endPoint(), and does not have same problem. I think it has something to do with virtual function, but I am not sure what.
Re: Strange compiler behaviour (compiler passes wrong argument)
It means you try to change a member of the class within a const function.
Calling the endPoint functions changes the state of the class.
Re: Strange compiler behaviour (compiler passes wrong argument)
Quote:
Originally Posted by
tbscope
It means you try to change a member of the class within a const function.
Calling the endPoint functions changes the state of the class.
Wow, how could I forget that. Thank you very much.