[Qt-interest] About QScopedPointer

Thiago Macieira thiago at kde.org
Fri May 13 15:33:00 CEST 2011


On Friday, 13 de May de 2011 03:33:45 Mihail Naydenov wrote:
> Problem is sometimes the pointer is not initialized when constructed.
> 
> It is later initialized by some func(Data** data)
> 
> Now I will have to do
> 
> Data* p = NULL;
> 
> func(&p);
> 
> QScopedPointer<Data, Release> sp(p);
> 
> // use sp, forget about p
> 
> Which is a bit cumbersome

Indeed. But you're attacking this problem from the wrong angle. You should 
change func to be:

	func(QScopedPointer<Data> &p)

So you can just do:
	QScopedPointer<Data> d;
	func(d);

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110513/37f72ff3/attachment.bin 


More information about the Qt-interest-old mailing list