移动 QWidget 派生的赋值运算符?
Move assignment operator for a QWidget derivate?
我有一个 QWidget 派生类,让我们假设标准 QWidget 示例
class MainWindow : public QMainWindow { //.. }
class MainWindow 填充 Rule of Five 是否有意义,我的意思是尤其是 Move 构造函数和移动赋值?
(因为 MainWindow 应该只创建一次)
没有。 QObject derived 类 不应被复制并使用 Q_DISABLE_COPY macro QObject and derived classes explicitly disable/hide the copy constructor and assignment operator by declaring them private. Possibly this has changed with recent releases and c++ 11 compatible compilers where they might now be declared deleted. See here
所以五法则出局了。查看 Qt 源代码,我找不到任何支持移动派生的 QObject 类 ...
最后一个好读物是Qt Objects: Identity vs Value
我有一个 QWidget 派生类,让我们假设标准 QWidget 示例
class MainWindow : public QMainWindow { //.. }
class MainWindow 填充 Rule of Five 是否有意义,我的意思是尤其是 Move 构造函数和移动赋值?
(因为 MainWindow 应该只创建一次)
没有。 QObject derived 类 不应被复制并使用 Q_DISABLE_COPY macro QObject and derived classes explicitly disable/hide the copy constructor and assignment operator by declaring them private. Possibly this has changed with recent releases and c++ 11 compatible compilers where they might now be declared deleted. See here
所以五法则出局了。查看 Qt 源代码,我找不到任何支持移动派生的 QObject 类 ...
最后一个好读物是Qt Objects: Identity vs Value