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

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

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

      1. <tfoot id='cVdys'></tfoot>

        <i id='cVdys'><tr id='cVdys'><dt id='cVdys'><q id='cVdys'><span id='cVdys'><b id='cVdys'><form id='cVdys'><ins id='cVdys'></ins><ul id='cVdys'></ul><sub id='cVdys'></sub></form><legend id='cVdys'></legend><bdo id='cVdys'><pre id='cVdys'><center id='cVdys'></center></pre></bdo></b><th id='cVdys'></th></span></q></dt></tr></i><div id='cVdys'><tfoot id='cVdys'></tfoot><dl id='cVdys'><fieldset id='cVdys'></fieldset></dl></div>
      2. C++ 模板和内联

        时间:2023-05-24
          <bdo id='3db3k'></bdo><ul id='3db3k'></ul>
          <tfoot id='3db3k'></tfoot>

        • <small id='3db3k'></small><noframes id='3db3k'>

        • <legend id='3db3k'><style id='3db3k'><dir id='3db3k'><q id='3db3k'></q></dir></style></legend>
            <tbody id='3db3k'></tbody>

                <i id='3db3k'><tr id='3db3k'><dt id='3db3k'><q id='3db3k'><span id='3db3k'><b id='3db3k'><form id='3db3k'><ins id='3db3k'></ins><ul id='3db3k'></ul><sub id='3db3k'></sub></form><legend id='3db3k'></legend><bdo id='3db3k'><pre id='3db3k'><center id='3db3k'></center></pre></bdo></b><th id='3db3k'></th></span></q></dt></tr></i><div id='3db3k'><tfoot id='3db3k'></tfoot><dl id='3db3k'><fieldset id='3db3k'></fieldset></dl></div>
                  本文介绍了C++ 模板和内联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  当我编写一个简单的(非模板)类时,如果函数实现是就地"提供的,它会自动被视为inline.

                  When I'm writing a simple (non-template) class, if the function implementation is provided "right in place", it's automatically treated as inline.

                  class A {
                     void InlinedFunction() { int a = 0; }
                     // ^^^^ the same as 'inline void InlinedFunction'
                  }
                  

                  当谈论基于模板的类时,这条规则怎么样?

                  What about this rule when talking about template-based classes?

                  template <typename T> class B {
                     void DontKnowFunction() { T a = 0; }
                     // Will this function be treated as inline when the compiler
                     // instantiates the template?
                  };
                  

                  另外,inline 规则是如何应用于非嵌套模板函数的,比如

                  Also, how is the inline rule applied to non-nested template functions, like

                  template <typename T> void B::DontKnowFunction() { T a = 0; }
                  
                  template <typename T> inline void B::DontKnowFunction() { T a = 0; }
                  

                  这里第一种和第二种情况会发生什么?

                  What would happen in the first and in the second case here?

                  谢谢.

                  推荐答案

                  据我所知,模板化函数是自动内联的.然而,现实是大多数现代编译器经常忽略内联限定符.在选择要内联的函数方面,编译器的优化启发式方法很可能比人类程序员做得更好.

                  Templated functions as far as I know are automatically inline. However, the reality is that most modern compilers regularly ignore the inline qualifier. The compiler's optimizing heuristics will most likely do a far better job of choosing which functions to inline than a human programmer.

                  这篇关于C++ 模板和内联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:工厂方法实现 - C++ 下一篇:提取 C++ 模板参数

                  相关文章

                  最新文章

                1. <tfoot id='YkJYe'></tfoot>
                    • <bdo id='YkJYe'></bdo><ul id='YkJYe'></ul>
                      <legend id='YkJYe'><style id='YkJYe'><dir id='YkJYe'><q id='YkJYe'></q></dir></style></legend>

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