• <tfoot id='2miAz'></tfoot>
      <legend id='2miAz'><style id='2miAz'><dir id='2miAz'><q id='2miAz'></q></dir></style></legend>
      • <bdo id='2miAz'></bdo><ul id='2miAz'></ul>
    1. <small id='2miAz'></small><noframes id='2miAz'>

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

        `=default` 移动构造函数是否等同于成员移动构造函数?

        Is a `=default` move constructor equivalent to a member-wise move constructor?(`=default` 移动构造函数是否等同于成员移动构造函数?)
        <tfoot id='CICZM'></tfoot>
          <bdo id='CICZM'></bdo><ul id='CICZM'></ul>
          • <legend id='CICZM'><style id='CICZM'><dir id='CICZM'><q id='CICZM'></q></dir></style></legend>
            <i id='CICZM'><tr id='CICZM'><dt id='CICZM'><q id='CICZM'><span id='CICZM'><b id='CICZM'><form id='CICZM'><ins id='CICZM'></ins><ul id='CICZM'></ul><sub id='CICZM'></sub></form><legend id='CICZM'></legend><bdo id='CICZM'><pre id='CICZM'><center id='CICZM'></center></pre></bdo></b><th id='CICZM'></th></span></q></dt></tr></i><div id='CICZM'><tfoot id='CICZM'></tfoot><dl id='CICZM'><fieldset id='CICZM'></fieldset></dl></div>
          • <small id='CICZM'></small><noframes id='CICZM'>

                  <tbody id='CICZM'></tbody>

                1. 本文介绍了`=default` 移动构造函数是否等同于成员移动构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这是吗

                  struct Example { 
                      string a, b; 
                  
                      Example(Example&& mE) : a{move(mE.a)}, b{move(mE.b)} { }
                      Example& operator=(Example&& mE) { a = move(mE.a); b = move(mE.b); return *this; } 
                  }
                  

                  相当于这个

                  struct Example { 
                      string a, b;
                  
                      Example(Example&& mE)            = default;
                      Example& operator=(Example&& mE) = default;
                  }
                  

                  ?

                  推荐答案

                  是的,两者是一样的.

                  但是

                  struct Example { 
                      string a, b; 
                  
                      Example(Example&& mE)            = default;
                      Example& operator=(Example&& mE) = default;
                  }
                  

                  此版本将允许您跳过正文定义.

                  This version will permits you to skip the body definition.

                  但是,在声明explicitly-defaulted-functions时必须遵循一些规则:

                  However, you have to follow some rules when you declare explicitly-defaulted-functions :

                  8.4.2 显式默认函数 [dcl.fct.def.default]

                  表单的一个函数定义:

                    attribute-specier-seqopt decl-specier-seqopt declarator virt-specier-seqopt = default ;
                  

                  被称为 明确默认 定义.一个明确默认的函数应该

                  is called an explicitly-defaulted definition. A function that is explicitly defaulted shall

                  • 成为一个特殊的成员函数,

                  • be a special member function,

                  具有相同的声明函数类型(除了可能不同的ref-qualifiers,并且除了在复制构造函数或复制赋值运算符的情况下,参数类型可能是引用到非常量 T",其中 T 是成员函数的类的名称),就像它已经被隐式声明一样,

                  have the same declared function type (except for possibly differing ref-qualifiers and except that in the case of a copy constructor or copy assignment operator, the parameter type may be "reference to non-const T", where T is the name of the member function’s class) as if it had been implicitly declared,

                  没有默认参数.

                  这篇关于`=default` 移动构造函数是否等同于成员移动构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Constructor initialization Vs assignment(构造函数初始化 Vs 赋值)
                  Has the new C++11 member initialization feature at declaration made initialization lists obsolete?(声明时新的 C++11 成员初始化功能是否使初始化列表过时了?)
                  Order of constructor call in virtual inheritance(虚继承中构造函数调用的顺序)
                  How to use sfinae for selecting constructors?(如何使用 sfinae 选择构造函数?)
                  Initializing a union with a non-trivial constructor(使用非平凡的构造函数初始化联合)
                  Why is the copy-constructor argument const?(为什么复制构造函数参数是常量?)

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

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

                              <tbody id='teU3I'></tbody>