#Unique pointers

9 messages · Page 1 of 1 (latest)

sour trench
#

I'm quite confused here. What points to the integer 42 now that we've "taken ownership"?

celest pikeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

#

@sour trench

Screenshots!

Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!

sour trench
#

say i want another thing to point to 42 now

#

do i add that inside the takeownership func

foggy kayak
#

It's the new pointer that pointers to 42.

#

Which gets destroyed immediately.

barren solar
# sour trench I'm quite confused here. What points to the integer 42 now that we've "taken own...

on the line with TakeOwnership(std::move(Number)); you transfer ownership of the "integer 42" from Number to the function parameter Num
that means Number owns nothing and points to nothing, whereas Num points to the "integer 42" and owns it
then when the function oTakeOwnership completes, Num is destroyed and takes down the "integer 42" it owned with it

the final line std::cout << *Number; is not a valid construct because you're cannot validly use * on a unique pointer that owns nothing

sour trench
#

!solved