<i id='zBpPY'><tr id='zBpPY'><dt id='zBpPY'><q id='zBpPY'><span id='zBpPY'><b id='zBpPY'><form id='zBpPY'><ins id='zBpPY'></ins><ul id='zBpPY'></ul><sub id='zBpPY'></sub></form><legend id='zBpPY'></legend><bdo id='zBpPY'><pre id='zBpPY'><center id='zBpPY'></center></pre></bdo></b><th id='zBpPY'></th></span></q></dt></tr></i><div id='zBpPY'><tfoot id='zBpPY'></tfoot><dl id='zBpPY'><fieldset id='zBpPY'></fieldset></dl></div>

      <legend id='zBpPY'><style id='zBpPY'><dir id='zBpPY'><q id='zBpPY'></q></dir></style></legend>

      • <bdo id='zBpPY'></bdo><ul id='zBpPY'></ul>

      <small id='zBpPY'></small><noframes id='zBpPY'>

      <tfoot id='zBpPY'></tfoot>
    1. 为什么调用这个复制构造函数而不是移动构造函

      时间:2023-10-06

          <tfoot id='uweOI'></tfoot>
            <legend id='uweOI'><style id='uweOI'><dir id='uweOI'><q id='uweOI'></q></dir></style></legend>

              <i id='uweOI'><tr id='uweOI'><dt id='uweOI'><q id='uweOI'><span id='uweOI'><b id='uweOI'><form id='uweOI'><ins id='uweOI'></ins><ul id='uweOI'></ul><sub id='uweOI'></sub></form><legend id='uweOI'></legend><bdo id='uweOI'><pre id='uweOI'><center id='uweOI'></center></pre></bdo></b><th id='uweOI'></th></span></q></dt></tr></i><div id='uweOI'><tfoot id='uweOI'></tfoot><dl id='uweOI'><fieldset id='uweOI'></fieldset></dl></div>
                <bdo id='uweOI'></bdo><ul id='uweOI'></ul>

              • <small id='uweOI'></small><noframes id='uweOI'>

                  <tbody id='uweOI'></tbody>
                本文介绍了为什么调用这个复制构造函数而不是移动构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                以下代码片段导致在我期望调用移动构造函数的地方调用复制构造函数:

                The following code snippet causes the copy constructor to be called where I expected the move constructor to be called:

                #include <cstdio>
                
                struct Foo
                {
                    Foo() { puts("Foo gets built!"); }
                    Foo(const Foo& foo) { puts("Foo gets copied!"); }
                    Foo(Foo&& foo) { puts("Foo gets moved!"); }
                };
                
                struct Bar { Foo foo; };
                Bar Meow() { Bar bar; return bar; }
                int main() { Bar bar(Meow()); }
                

                在 VS11 Beta 上,在调试模式下,打印:

                On VS11 Beta, in debug mode, this prints:

                Foo gets built!
                Foo gets copied!
                Foo gets copied!
                

                我检查了标准,Bar 似乎满足自动生成默认移动构造函数的所有要求,但这似乎不会发生,除非有另一个原因导致无法移动对象.我在这里看到了很多与移动和复制构造函数相关的问题,但我认为没有人遇到过这个具体问题.

                I checked the standard and Bar seems to meet all requirements to have a default move constructor automatically generated, yet that doesn't seem to happen unless there's another reason why the object cannot be moved. I've seen a lot of move and copy constructor related questions around here but I don't think anyone has had this specific issue.

                关于这里发生了什么的任何指示?这是标准行为吗?

                Any pointers on what's going on here? Is this standard behaviour?

                推荐答案

                不幸的是,VS11 没有提供默认的移动构造函数.请参阅备注部分中的移动语义- 引用:

                Unfortunately, VS11 doesn't provide a default move constructor. See Move Semantics in the Remarks section - to quote:

                与默认的复制构造函数不同,编译器不提供默认移动构造函数.

                Unlike the default copy constructor, the compiler does not provide a default move constructor.

                这篇关于为什么调用这个复制构造函数而不是移动构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:为什么 rand() 编译时不包含 cstdlib 或使用命名空间 下一篇:尝试使用 std::get_time 解析 YYMMDD 并失败

                相关文章

                最新文章

                <legend id='iDnKp'><style id='iDnKp'><dir id='iDnKp'><q id='iDnKp'></q></dir></style></legend>

                  <small id='iDnKp'></small><noframes id='iDnKp'>

                  <i id='iDnKp'><tr id='iDnKp'><dt id='iDnKp'><q id='iDnKp'><span id='iDnKp'><b id='iDnKp'><form id='iDnKp'><ins id='iDnKp'></ins><ul id='iDnKp'></ul><sub id='iDnKp'></sub></form><legend id='iDnKp'></legend><bdo id='iDnKp'><pre id='iDnKp'><center id='iDnKp'></center></pre></bdo></b><th id='iDnKp'></th></span></q></dt></tr></i><div id='iDnKp'><tfoot id='iDnKp'></tfoot><dl id='iDnKp'><fieldset id='iDnKp'></fieldset></dl></div>

                    <tfoot id='iDnKp'></tfoot>
                      <bdo id='iDnKp'></bdo><ul id='iDnKp'></ul>