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

      <tfoot id='Zs6nH'></tfoot>

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

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

      1. 为什么有些人更喜欢“T const"?超过“const T"?

        Why do some people prefer quot;T constamp;quot; over quot;const Tamp;quot;?(为什么有些人更喜欢“T const?超过“const T?)

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

        <legend id='Bgr9J'><style id='Bgr9J'><dir id='Bgr9J'><q id='Bgr9J'></q></dir></style></legend>
            <tbody id='Bgr9J'></tbody>
        • <tfoot id='Bgr9J'></tfoot>

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

            <bdo id='Bgr9J'></bdo><ul id='Bgr9J'></ul>
                1. 本文介绍了为什么有些人更喜欢“T const"?超过“const T"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  所以,我意识到 const T&T const& 是相同的,都表示对 const T 的引用.在这两种情况下,引用也是常量(与指针不同,不能重新分配引用).我观察到,以我有限的经验,大多数 C++ 程序员使用 const T&,但我遇到过一些使用 T const& 的人.我使用 const T& 只是因为我是那样学的,所以 T const& 对我来说看起来有点好笑.您使用您使用的变体的原因是什么?你们中是否有人在编码标准要求使用一种变体而不是另一种变体的组织工作?

                  So, I realize that const T& and T const& are identical and both mean a reference to a const T. In both cases, the reference is also constant (references cannot be reassigned, unlike pointers). I've observed, in my somewhat limited experience, that most C++ programmers use const T&, but I have come across a few people who use T const&. I use const T& simply because I learned it that way, and so T const& looks a little bit funny to me. What is the reason that you use the variant that you use? Do any of you work at an organization for which the coding standards mandate the use of one variant over the other?

                  编辑
                  根据这些答案,在两者之间进行选择的一个原因似乎是您想像编译器(从右到左)还是像英语(从左到右)一样阅读它.如果像编译器一样读取它,那么T const&"读作& (reference) const (to a constant) T (of type T)".如果从左到右读起来像英语一样,那么const T&"读作引用形式的 T 类型常量对象".我更喜欢像读英文散文一样阅读它,但我当然可以看到以编译器的方式解释它的意义.

                  Edit
                  Based on the answers, it would appear that one reason for choosing between the two is whether you want to read it like the compiler (right-to-left) or like English (left-to-right). If one reads it like the compiler, then "T const&" reads as "& (reference) const (to a constant) T (of type T)". If one reads it like English, from left-to-right, then "const T&" is read as "a constant object of type T in the form of a reference". I prefer to read it like English prose, but I can certainly see the sense in interpreting it the way that the compiler does.

                  没有人回答组织或编码标准的问题,但我强烈怀疑大多数组织不会强制要求一个而不是另一个,尽管他们可能会努力保持一致性.

                  No one has answered the organization or coding standards question, but I strongly suspect that most organizations do not mandate one over the other, although they might strive for consistency.

                  推荐答案

                  我认为有些人只是喜欢从右到左阅读声明.const 适用于左边的标记,除非那里什么都没有,而且它适用于右边的标记.因此,const T& 包含except"子句,可能会被认为更复杂(实际上两者都应该很容易理解).

                  I think some people simply prefer to read the declarations from right to left. const applies to the left-hand token, except when there is nothing there and it applies on the right-hand token. Hence const T& involves the "except"-clause and can perhaps be thought more complicated (in reality both should be as easy to understand).

                  比较:

                  const T* p;  (pointer to T that is const)
                  T const* p;  (pointer to const T) //<- arguable more natural to read
                  T* const p;  (const pointer to T)
                  

                  这篇关于为什么有些人更喜欢“T const"?超过“const T"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)
                2. <i id='UHB1K'><tr id='UHB1K'><dt id='UHB1K'><q id='UHB1K'><span id='UHB1K'><b id='UHB1K'><form id='UHB1K'><ins id='UHB1K'></ins><ul id='UHB1K'></ul><sub id='UHB1K'></sub></form><legend id='UHB1K'></legend><bdo id='UHB1K'><pre id='UHB1K'><center id='UHB1K'></center></pre></bdo></b><th id='UHB1K'></th></span></q></dt></tr></i><div id='UHB1K'><tfoot id='UHB1K'></tfoot><dl id='UHB1K'><fieldset id='UHB1K'></fieldset></dl></div>

                      <bdo id='UHB1K'></bdo><ul id='UHB1K'></ul>
                    • <small id='UHB1K'></small><noframes id='UHB1K'>

                      <legend id='UHB1K'><style id='UHB1K'><dir id='UHB1K'><q id='UHB1K'></q></dir></style></legend>
                        <tbody id='UHB1K'></tbody>
                          • <tfoot id='UHB1K'></tfoot>