0

I'm trying to compile a project which is written with Qt Project components in C++ language I've following declaration in one of the classes "DetectAll" but compiler complains about the code syntax and stops exactly at the PointIndex().

From that code I understand that PointIndex is a variable which is intrinsic for Qt Project and is passed as 2nd argument in function DetectAll. But compiler mentions also the QPair which doesn't make sense for me, can you help me to spot what am I actually doing wrong here ?

Below is original code and compiler error

protected:
.....
bool detectAll(const QPointF& pos, PointIndex& result = PointIndex());

/////////////

D:\....\MAT\Skeleton_source\sswidget.h:87: error: could not convert 'QPair<int, int>()'
 from 'SSWidget::PointIndex {aka QPair<int, int>}' to 'SSWidget::PointIndex& {aka QPair<int, int>&}'
 bool detectAll(const QPointF& pos, PointIndex& result = PointIndex());
                                                                    ^
Sonya Blade
  • 399
  • 7
  • 24

2 Answers2

1

Change

PointIndex& result = PointIndex()

to

PointIndex result = PointIndex()

In your parameter decl. Or remove the default value. You cannot bind a non const reference to a temporary.

You're assigning a reference a default value, which the compiler is complaining about. Also, it seems that SSWidget::PointIndex is typedefed to QPair<int, int> which is why you see that mentioned.

Related SO question here.

Community
  • 1
  • 1
NG.
  • 22,560
  • 5
  • 55
  • 61
0

The compiler error you receive is concerned with pointers. Are you sure you should include the & symbol in the deceleration?

The SSWidget::PointIndex is implemented as a QPair, with a template.

Trygve
  • 493
  • 3
  • 15