Pimpl copying

Peter Kümmel syntheticpp at gmx.net
Fri Jul 14 09:52:19 BST 2006


André Wöbbeking wrote:
>> I fear kdelibs is full of this bug and think we should catch
>> such constructs at compile time.
> 
> Many classes with pimpls are subclasses of QObject which can't be 
> copied/assigned. Some other classes use QSharedDataPointer. In both 
> cases you don't have that problem.
> 

But is also does not hurt to disable copying again.

>> Shouldn't we introduce a coding policy something like this:
> 
> I think people should be aware of this pitfall (could anyone add this to 
> http://developer.kde.org/policies/librarypolicy.html?).
> 
>> This introduces a new macro KDE_PIMPL_COPYABLE
>> which declares the pimpl AND the copy functions.
>>
>> KDE_PIMPL_UNCOPYABLE declares the copy functions
>> as private, so we get an error at compile time.
>>
>> Or is there already a Qt way to handle this?
> 
> Q_DISABLE_COPY

Which could be and was forgotten.

Isn't it better to also use a macro for the pimpl?

Then the naming of the pimpl classes is consisted,
also we could delete one item from the TODO list:

- Change all FooPrivate *d; -> Private * const d; and place initialization
  in the constructor (for classes that would benefit from this).  To help catch silly
  mistakes since d should never change.


I think this macros could also become a official "Q_" macro.


> 
> Cheers,
> André
> 
> 





More information about the kde-core-devel mailing list