Qt变量初始化,为何要与声明的次序保持一致?
VC里没此限制,C++标准也没此要求。Qt却是这样的,这是为何呢?
这搞的经常因这个改来改去的。
#include <QPainter>#include <QMouseEvent>#define CAPTURE_WIDTH 98#define CAPTURE_HEIGHT 125editPainter::editPainter(QWidget* pParent) : QWidget(pParent) , m_pPixmapSource(NULL) , m_pPixmapCaptured(NULL) , m_bMousePressed(false) , m_bDisChangeDir(false) , m_enAction(NO_ACTION) , m_eumScaleType(SCALE_FIX){ m_pPixmapCaptured = new QPixmap(CAPTURE_WIDTH, CAPTURE_HEIGHT); setMouseTracking(true); m_ptLast = QPoint(0, 0);}void editPainter::setImagePath(QString strPath){ if (NULL != m_pPixmapSource) { delete m_pPixmapSource; m_pPixmapSource = NULL; } m_pPixmapSource = new QPixmap(); bool bRet = m_pPixmapSource->load(strPath); if (bRet) { prePaintRect(); capturePixmap(); repaint(); //刷新 } else { if (NULL != m_pPixmapSource) { delete m_pPixmapSource; m_pPixmapSource = NULL; } }}