KSharedPtr breakage

David Faure faure at kde.org
Mon Oct 24 10:22:12 BST 2005


On Monday 24 October 2005 01:47, Frerich Raabe wrote:
> On Sunday 23 October 2005 21:21, David Faure wrote:
> > On Sunday 23 October 2005 20:28, Frerich Raabe wrote:
> > > How about making KSycocaEntry (and all the stuff that inherits it -
> > > KServiceType, KProtocolInfo et cetera) classes with value semantics,
> > > making it do all the reference counting internally. So you'd have a
> > > 'KServiceType KSycocaFactory::findServiceByName( const QString & )'
> > > function and so on.
> > >
> > > Besides the nice side-effect that value semantics don't even trigger the
> > > whole 'Who owns this thing?' thing, it would solve the problem with
> > > covariant return types which you get when returning a SharedPtr<Foo>
> > > instead of a Foo*.
> >
> > Sounds very good to me.
> 
> Unfortunately I lied - it doesn't solve the covariant return problem at all. 
> It only works if you return *pointers*, not actual objects. :-(

I don't see the problem. This is very much like QDom or KDom.
We could return a KServiceType instance by value, and the caller could do
 if (myServiceType.isMimeType() ) {
    KMimeType mime = myServiceType.toMimeType();
    ..
 }

Ah, you meant inside the factories themselves? Those would still
use pointers (like in your '#define WORKS' case). The wrapping into
KSharedPtr can happen after the factory has created the thing.
And then pure virtuals still work too.

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).





More information about the kde-core-devel mailing list