Question on move constructor
Graziano Servizi
Graziano.Servizi@bo.infn.it
Mon Jan 28 14:46:00 GMT 2013
Hi,
My name is Graziano Servizi, Associate Professor in Mathematical Physics
at Bologna University, Italy.
I'm using release 4.7.2 of GNU-GCC on a Fedora 17 Linux System.
I would ask you a question about move constructors, namely
WHEN are they called?
I got an example on Internet (attached) and the output they claim to be
obtained (also attached) is NOT reproduced on my system (it is attached
as well).
I also tried some checks of my own and I was unable to call a move
constructor that I wrote in my classes (I presume in a correct way,
since the compiler didn't complain). It seems to me that, anytime the
standard 2011 claims that a move constructor should be called, the
"classical" copy constructor is called instead, unless one explicitly
use a call to the std::move function. Is this correct or wrong?
Answers are kindly requested and welcome.
Graziano Servizi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sample_code.C
Type: text/x-c++src
Size: 3157 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20130128/fd46d03e/attachment.bin>
-------------- next part --------------
In MemoryBlock(size_t). length = 25.
In MemoryBlock(MemoryBlock&&). length = 25. Moving resource.
In ~MemoryBlock(). length = 0.
In MemoryBlock(size_t). length = 75.
In MemoryBlock(MemoryBlock&&). length = 25. Moving resource.
In ~MemoryBlock(). length = 0.
In MemoryBlock(MemoryBlock&&). length = 75. Moving resource.
In ~MemoryBlock(). length = 0.
In MemoryBlock(size_t). length = 50.
In MemoryBlock(MemoryBlock&&). length = 50. Moving resource.
In MemoryBlock(MemoryBlock&&). length = 50. Moving resource.
In operator=(MemoryBlock&&). length = 75.
In operator=(MemoryBlock&&). length = 50.
In ~MemoryBlock(). length = 0.
In ~MemoryBlock(). length = 0.
In ~MemoryBlock(). length = 25. Deleting resource.
In ~MemoryBlock(). length = 50. Deleting resource.
In ~MemoryBlock(). length = 75. Deleting resource.
-------------- next part --------------
In MemoryBlock(size_t). length = 25.
In MemoryBlock(MemoryBlock&&). length = 25. Moving resource.
In ~MemoryBlock(). length = 0.
In MemoryBlock(size_t). length = 75.
In MemoryBlock(MemoryBlock&&). length = 75. Moving resource.
In MemoryBlock(const MemoryBlock&). length = 25. Copying resource.
In ~MemoryBlock(). length = 25. Deleting resource.
In ~MemoryBlock(). length = 0.
In MemoryBlock(size_t). length = 50.
In MemoryBlock(MemoryBlock&&). length = 50. Moving resource.
In MemoryBlock(const MemoryBlock&). length = 25. Copying resource.
In MemoryBlock(const MemoryBlock&). length = 75. Copying resource.
In ~MemoryBlock(). length = 25. Deleting resource.
In ~MemoryBlock(). length = 75. Deleting resource.
In ~MemoryBlock(). length = 0.
In ~MemoryBlock(). length = 25. Deleting resource.
In ~MemoryBlock(). length = 50. Deleting resource.
In ~MemoryBlock(). length = 75. Deleting resource.
More information about the Gcc-help
mailing list