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

    1. <tfoot id='72n5T'></tfoot>

      1. <small id='72n5T'></small><noframes id='72n5T'>

          <bdo id='72n5T'></bdo><ul id='72n5T'></ul>

        常量引用和普通参数的区别

        Difference between const reference and normal parameter(常量引用和普通参数的区别)
            <tbody id='nLjdD'></tbody>
          <i id='nLjdD'><tr id='nLjdD'><dt id='nLjdD'><q id='nLjdD'><span id='nLjdD'><b id='nLjdD'><form id='nLjdD'><ins id='nLjdD'></ins><ul id='nLjdD'></ul><sub id='nLjdD'></sub></form><legend id='nLjdD'></legend><bdo id='nLjdD'><pre id='nLjdD'><center id='nLjdD'></center></pre></bdo></b><th id='nLjdD'></th></span></q></dt></tr></i><div id='nLjdD'><tfoot id='nLjdD'></tfoot><dl id='nLjdD'><fieldset id='nLjdD'></fieldset></dl></div>
          <tfoot id='nLjdD'></tfoot>

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

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

                  <bdo id='nLjdD'></bdo><ul id='nLjdD'></ul>
                  本文介绍了常量引用和普通参数的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  void DoWork(int n);
                  void DoWork(const int &n);
                  

                  有什么区别?

                  推荐答案

                  当你传递一个大的 struct/class 时区别更加突出:

                  The difference is more prominent when you are passing a big struct/class:

                  struct MyData {
                      int a,b,c,d,e,f,g,h;
                      long array[1234];
                  };
                  void DoWork(MyData md);
                  void DoWork(const MyData& md);
                  

                  当您使用 use 'normal' 参数时,您将按值传递参数,从而创建您传递的参数的副本.如果使用的是const引用,则是通过引用传递,不会复制原始数据.

                  When you use use 'normal' parameter, you pass the parameter by value and hence creating a copy of the parameter you pass. If you are using const reference, you pass it by reference and the original data is not copied.

                  在这两种情况下,不能在函数内部修改原始数据.

                  In both cases, the original data cannot be modified from inside the function.


                  在某些情况下,原始数据可能会被修改,正如 Charles Bailey 在他的 答案.

                  这篇关于常量引用和普通参数的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Constructor initialization Vs assignment(构造函数初始化 Vs 赋值)
                  Is a `=default` move constructor equivalent to a member-wise move constructor?(`=default` 移动构造函数是否等同于成员移动构造函数?)
                  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(使用非平凡的构造函数初始化联合)
                • <small id='viKst'></small><noframes id='viKst'>

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