Originally Posted by wysota Qt Code: Switch view class Object {public: Object() { d = new ObjectPrivate; } Object(const Object &other) : d(other.d){ } int x() const { return d->x; } void setX(int x) { d->x = x; } Object childAt(int i) const { return d->children.at(i); } void addChild(Object o) { d->children.append(o); o.d->parent = *this; } Object& operator=(const Object &other) { d = other.d; return *this;}private: QSharedPointer<ObjectPrivate> d;}; class ObjectPrivate {public: int x; Object parent; QList<Object> children;}; class Object { public: Object() { d = new ObjectPrivate; } Object(const Object &other) : d(other.d){ } int x() const { return d->x; } void setX(int x) { d->x = x; } Object childAt(int i) const { return d->children.at(i); } void addChild(Object o) { d->children.append(o); o.d->parent = *this; } Object& operator=(const Object &other) { d = other.d; return *this;} private: QSharedPointer<ObjectPrivate> d; }; class ObjectPrivate { public: int x; Object parent; QList<Object> children; }; To copy to clipboard, switch view to plain text mode It's very interesting realization - it's pimpl But I see BUG in this code ) - it seems recursive parent destruction - you must use QWeakPointer for parent.
class Object {public: Object() { d = new ObjectPrivate; } Object(const Object &other) : d(other.d){ } int x() const { return d->x; } void setX(int x) { d->x = x; } Object childAt(int i) const { return d->children.at(i); } void addChild(Object o) { d->children.append(o); o.d->parent = *this; } Object& operator=(const Object &other) { d = other.d; return *this;}private: QSharedPointer<ObjectPrivate> d;}; class ObjectPrivate {public: int x; Object parent; QList<Object> children;};
class Object { public: Object() { d = new ObjectPrivate; } Object(const Object &other) : d(other.d){ } int x() const { return d->x; } void setX(int x) { d->x = x; } Object childAt(int i) const { return d->children.at(i); } void addChild(Object o) { d->children.append(o); o.d->parent = *this; } Object& operator=(const Object &other) { d = other.d; return *this;} private: QSharedPointer<ObjectPrivate> d; }; class ObjectPrivate { public: int x; Object parent; QList<Object> children; };
Forum Rules
Bookmarks