POV-Ray : Newsgroups : povray.off-topic : Wikipath : Re: Wikipath Server Time
1 Oct 2024 00:08:00 EDT (-0400)
  Re: Wikipath  
From: Fredrik Eriksson
Date: 2 Sep 2008 17:06:15
Message: <op.ugvgwof77bxctx@e6600>
On Tue, 02 Sep 2008 22:22:46 +0200, Darren New <dne### [at] sanrrcom> wrote:
> One of my problems with learning C++ is the number of places where,  
> instead of saying "This is what this feature does", people say "this is  
> how you use this feature."

Perhaps because the rules are sometimes so complex that few really know  
exactly what a particular feature does under all conditions. It is much  
easier to say "if you do it like this, it works" than to list all the many  
cases where it does something slightly or vastly different.



> What is a "move constructor"? When would you be "moving" some value?

"Moving" a value is useful when you know that the source value will be  
discarded anyway right after the copy is performed, e.g. if it is the  
return value of a function. Many objects that are expensive to copy can be  
"moved" much more efficiently.

Also, some types of objects are inherently non-copyable -- because they  
hold/represent some unique resource -- but they could still be "movable".



> If you destructively alter something with aliases, aren't you in trouble?

Hence the need to distinguish temporaries from regular const objects. Note  
that non-temporaries can also be bound to r-value references, but not  
implicitly.



> Isn't that what the whole "ownership" concept is supposed to prevent?

A move constructor would transfer ownership of whatever the source object  
is holding. Look to 'std::auto_ptr' for something resembling an example.




A more verbose summary can be found here:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2027.html


-- 
FE


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.