I noticed some code of a colleague today that initialized class variables in the initialization. However it was causing a warning, he says because of the order they are in. My question is why is it better to do variable initialization where it currently is and not within the curly brackets?
DiagramScene::DiagramScene( int slideNo, QRectF screenRect, MainWindow* parent )
: QGraphicsScene( screenRect, parent ),
myParent( parent ),
slideUndoImageCurrentIndex(-1),
nextGroupID(0),
m_undoInProgress(false),
m_deleteItemOnNextUndo(0)
line(0),
path(0)
{
/* Setup default brush for background */
scDetail->bgBrush.setStyle(Qt::SolidPattern);
scDetail->bgBrush.setColor(Qt::white);
setBackgroundBrush(scDetail->bgBrush);
}
const
members must be initialised in the initialiser list, because you can't assign to a reference or to a const
member.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With