[Interest] assigning to QSharedPointer

Hamish Moffatt hamish at risingsoftware.com
Tue May 30 02:50:23 CEST 2017


Which of the following three ways to create a new object and manage it 
with QSharedPointer is preferable?

class Foo;

QSharedPointer<Foo> f1, f2, f3; // class members


f1.reset(new Foo);

f2 = QSharedPointer<Foo>::create(); // or even f2 = f2.create()

f3.swap(QSharedPointer<Foo>::create()); // or f3.swap(f3.create()))


I find #2 the easiest to read. Do #2 and #3 perform any differently? 
Anything else to consider?



Hamish




More information about the Interest mailing list