Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17625

Best practices and std::unique_ptr

$
0
0

Trying to use best practices for C++ and I see that you should be using std::unique_ptr now. And coming from using raw pointers only I have some questions.

When it comes to returning functions, if I return a std::unique_ptr like:

//Declared as member variable of MyObject class
std::unique_ptr<InternalObject> internalObject;

//Return function of MyObject class to get internalObject as a std::unique_ptr
std::unique_ptr<InternalObject> getInternalObject() {
	return internalObject;
}

What am I really returning here? I read that this more or less “gives up” ownership of the pointer and does std::move. If this is true what happens to my internalObject …


Viewing all articles
Browse latest Browse all 17625

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>