Doc: Modernize QSharedDataPointer Example for Rule of Compliance
Replaced the manually defined copy constructor with = default to improve clarity and maintainability.Added a default copy assignment operator to ensure consistency,as copy constructor and copy assignment should be defined as a pair.Also included defaulted move constructor and move assignment operator in accordance with the rule of 6,ensuring the example is modern,complete,and suitable for educational purposes. Fixes: QTBUG-111392 Change-Id: Ia7cfccfc46182d8d9102868fc93dc0ebd9649a32 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
parent
045eb2179c
commit
b52c0dafd8
@ -6,6 +6,7 @@
|
||||
|
||||
//! [0]
|
||||
#include <QSharedData>
|
||||
#include <QSharedDataPointer>
|
||||
#include <QString>
|
||||
|
||||
class EmployeeData : public QSharedData
|
||||
@ -14,7 +15,7 @@ class EmployeeData : public QSharedData
|
||||
EmployeeData() : id(-1) {}
|
||||
EmployeeData(const EmployeeData &other)
|
||||
: QSharedData(other), id(other.id), name(other.name) {}
|
||||
~EmployeeData() { }
|
||||
~EmployeeData() = default;
|
||||
|
||||
int id;
|
||||
QString name;
|
||||
@ -32,10 +33,14 @@ class Employee
|
||||
setName(name);
|
||||
}
|
||||
//! [2] //! [7]
|
||||
Employee(const Employee &other)
|
||||
: d (other.d)
|
||||
{
|
||||
}
|
||||
Employee(const Employee &other) = default;
|
||||
Employee &operator=(const Employee &other) = default;
|
||||
|
||||
Employee(Employee &&other) = default;
|
||||
Employee &operator=(Employee &&other) = default;
|
||||
|
||||
~Employee() = default;
|
||||
|
||||
//! [7]
|
||||
//! [3]
|
||||
void setId(int id) { d->id = id; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user