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

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

    1. <legend id='oZuA9'><style id='oZuA9'><dir id='oZuA9'><q id='oZuA9'></q></dir></style></legend>

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

      1. 为什么调用这个复制构造函数而不是移动构造函数?

        时间:2023-07-02
        <tfoot id='K3fnN'></tfoot>

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

            • <bdo id='K3fnN'></bdo><ul id='K3fnN'></ul>
                <legend id='K3fnN'><style id='K3fnN'><dir id='K3fnN'><q id='K3fnN'></q></dir></style></legend>

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

                    <tbody id='K3fnN'></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.

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

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

                  相关文章

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

                  <small id='8dRmR'></small><noframes id='8dRmR'>

                1. <legend id='8dRmR'><style id='8dRmR'><dir id='8dRmR'><q id='8dRmR'></q></dir></style></legend>

                  <tfoot id='8dRmR'></tfoot>