[Qt-interest] Const correctness with QSharedPointer
Colin Kern
colin.kern at gmail.com
Tue Dec 8 01:25:11 CET 2009
On Mon, Dec 7, 2009 at 6:03 PM, Glenn Hughes <ghughes02138 at gmail.com> wrote:
> You'd have to say this:
>
> QSharedPointer<A> p(new B());
> func(p);
This doesn't preserve polymorphism since if there was another function:
void func2(QSharedPointer<B> p);
I couldn't pass p to this function.
> QSharedPointer<B> p(new B());
> func( QSharedPointer<A>( p.get() ) );
This is a better solution I think. Actually, I just found the
staticCast() member function which I think would be used like this:
func( p.staticCast<A>() );
Is this equivalent to what you have, or are there pros/cons to one vs.
the other?
Thanks,
Colin
More information about the Qt-interest-old
mailing list