Talk:Policies/Library Code Policy/Shared D-Pointer Example

From KDE TechBase
Revision as of 16:12, 12 March 2009 by Tampakrap (talk | contribs) (Can someone please give an example how to implement the copy constructor correctly)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Can someone please give an example how to implement the copy constructor correctly in the base and derived class? I spent some hours to find out how it could work and I'm doing it like this:

Base(const Base &other)

: d_ptr(new BasePrivate(other.d_func()->property1,
   other.d_func()->property2...)

{ }

Derived(const Derived &other)

: Base(*new DerivedPrivate(other.d_func()->property1,
   other.property2, other.d_func()->property3....))

{ }

It works but somehow it doesn't feel like it was meant that way.