What is the purpose of the virtual operator () () here?

I am trying to change the code that I found , but I am blocked by the lack of understanding of the purpose, importance and / or relevance of this virtual operator:

  • Can someone give an idea of ​​why this operator is necessary or useful?
  • I think it takes values parentItem(), rect_and resizer_as parameters, and then changes the value resizer_?

Constructor in .h:

virtual void operator()(QGraphicsItem* item, const QRectF& rect) = 0;

Call in .cpp:

(*resizer_)(parentItem(), rect_);

Cropped context for constructor for reference:

class SizeGripItem : public QGraphicsItem
{
    private:

        class HandleItem : public QGraphicsRectItem
        {
            public:
                HandleItem(int positionFlags, SizeGripItem* parent);

            private:    
                SizeGripItem* parent_;
        };

    public:
        class Resizer
        {
            public:
                virtual void operator()(QGraphicsItem* item,
                                        const QRectF& rect) = 0;
        };

        SizeGripItem(Resizer* resizer = 0, QGraphicsItem* parent = 0);
        virtual ~SizeGripItem();

    private:
        void doResize();
        QRectF rect_;
        Resizer* resizer_;
};
+4
source share
2 answers

For point 2, consider this line:

(*resizer_)(parentItem(), rect_);

resizer_ T, *resizer T.
operator(), , () decltype(parentItem()) decltype(rect_), , .
, :

resizer_->operator()(parentItem(), rect_);

resizer_.

- , ?

, , .
.
, . .

+3

Resizer ( ). ++ 11. , . :

class Resizer {
public:
  virtual void operator()(QGraphicsItem* item, const QRectF& rect) = 0;
  virtual ~Resizer() {}
};

:

void invokeResizer(Resizer * resizer, QGraphicsItem * item, const QRectF & rect) {
  (*resizer)(item, rect);
}

operator()(QGraphicsItem*,const QRectF&) Resizer.

std::function<void(QGraphicsItem*, const QRectF &)>.

+4

Source: https://habr.com/ru/post/1659631/


All Articles