On Wed, 18 Apr 2012 13:25:43 -0500
"David C. Rankin" <drankinatty(a)suddenlinkmail.com> wrote:
On 04/17/2012 06:22 PM, David C. Rankin wrote:
Darrell, all
I'm making an attempt at fixing k3b for gcc47. If anyone else has already done
this please stop me. It is part of bug 958.
This is another redeclaration issue, but it is not the same type of simple
iterator issue I've seen earlier. The build of k3b fails on gcc47 with:
k3baudioeditorwidget.cpp: In member function 'virtual void
K3bAudioEditorWidget::mousePressEvent(TQMouseEvent*)':
k3baudioeditorwidget.cpp:674:12: error: redeclaration of
'K3bAudioEditorWidget::Range* r'
k3baudioeditorwidget.cpp:668:14: error: 'K3bAudioEditorWidget::Range* r'
previously declared here
It is complaining about 'r' being declared twice below. This looks more like a
reassignment than a redeclaration to me. How do we properly fix it?. If all we
care about here is 'r' having function scope, can't I just get rid of the
'Range* ' typecast following the else { ? Or do I have to change 'r' to
'not_r'
following the else?
If I'm understanding the code correctly, I would probably move the declaration
of r outside the condition for the if, that is:
void K3bAudioEditorWidget::mousePressEvent( TQMouseEvent* e ) {
m_draggedRange = 0;
m_draggedMarker = 0;
bool end;
Range* r = findRangeEdge(e->pos(), &end);
if (r) {
m_draggedRange = r;
m_draggingRangeEnd = end;
}
else {
r = findRange( e->pos() );
d->movedRange = r;
d->lastMovePosition = posToMsf( e->pos().x() );
m_draggedMarker = findMarker( e->pos() );
}
setSelectedRange( r );
TQFrame::mousePressEvent(e);
}
To my eye, that's clearer than the original. I would never declare a variable
inside a condition for a branching construct, even if it's legal to do so (the
technique has valid applications in loop constructs, but here it just serves to
muddy the scoping). </opinionated>
Alternatively, basic scoping rules suggest:
void K3bAudioEditorWidget::mousePressEvent( TQMouseEvent* e )
{
m_draggedRange = 0;
m_draggedMarker = 0;
bool end;
if( Range* r = findRangeEdge( e->pos(), &end ) ) {
m_draggedRange = r;
m_draggingRangeEnd = end;
setSelectedRange( r );
}
else {
Range* r_two = findRange( e->pos() );
d->movedRange = r_two;
d->lastMovePosition = posToMsf( e->pos().x() );
setSelectedRange( r_two );
m_draggedMarker = findMarker( e->pos() );
}
TQFrame::mousePressEvent(e);
}