User: Password:
Subscribe / Log in / New account

C vs C++

C vs C++

Posted May 21, 2014 21:07 UTC (Wed) by jwakely (guest, #60262)
In reply to: C vs C++ by ehiggs
Parent article: Clasen: Introducing GtkInspector

Returning a unique_ptr is better than a raw pointer - it's safe-by-default and also explicit that there is ownership transfer going on. Returning a raw pointer has no advantage over unique_ptr.

If you want to take ownership from a unique_ptr and get a raw pointer that you own it's easy, call release(). You can't do that with a shared_ptr as there could be other owners and there's no way to force them to release their reference.

(Log in to post comments)

Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds