<tfoot id='VI3It'></tfoot><legend id='VI3It'><style id='VI3It'><dir id='VI3It'><q id='VI3It'></q></dir></style></legend>
  • <small id='VI3It'></small><noframes id='VI3It'>

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

        运算符<<中的执行顺序

        Order of execution in operator lt;lt;(运算符中的执行顺序)

          <tbody id='c3UtR'></tbody>

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

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

              • <tfoot id='c3UtR'></tfoot>
                • <bdo id='c3UtR'></bdo><ul id='c3UtR'></ul>

                • <small id='c3UtR'></small><noframes id='c3UtR'>

                  本文介绍了运算符<<中的执行顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我很难理解下面代码中的调用顺序.我期待看到下面的输出

                  I have difficulties in understanding the sequence of calls in the code below. I was expecting to see the output below

                      A1B2
                  

                  虽然我可以看到我得到的输出是

                  While I can see that the output I get is

                      BA12
                  

                  我认为调用 std::cout<<b->fooA()<fooB()< 等价于 call

                  I thought that the call std::cout<< b->fooA() << b->fooB() << std::endl was equivalent to call

                    std::cout.operator<<( b->fooA() ).operator<< ( b->fooB() )
                  

                  但我可以看出事实并非如此.你能帮助我更好地理解它是如何工作的以及与全局 operator<< 的关系吗?这是此序列中的最后一次调用吗?

                  but I can see that this is not the case. Can you help me understanding better how this does it work and the relationship with the global operator<<? Is this last ever called in this sequence?

                  #include <iostream>
                  
                  struct cbase{
                      int fooA(){
                          std::cout<<"A";
                          return 1;
                      }
                      int fooB(){
                          std::cout <<"B";
                          return 2;
                      }
                  };
                  
                  void printcbase(cbase* b ){
                      std::cout << b->fooA() << b->fooB() << std::endl;
                  }
                  
                  int main(){
                      cbase b;
                      printcbase( &b );
                  }
                  

                  推荐答案

                  编译器可以对函数 printcbase() 求值:

                  The compiler can evaluate the function printcbase() as this:

                  void printcbase(cbase* b ){
                      int a = b->FooA();    // line 1
                      int b = b->FooB();    // line 2
                      std::cout << a;       // line 3
                      std::cout << b;       // line 4
                      stc::cout << std::endl;
                  }
                  

                  或标记为 1 - 4 行的许多排列中的一些.您只能保证第 1 行在第 3 行之前完成,第 2 行在第 4 行之前完成(当然还有第 3 行在第 4 行之前).标准没有多说,确实可以预期不同的 C++ 编译器会产生不同的结果.

                  or some of many permutatins of lines marked as 1 - 4. You are only guaranteed that that the line 1 is done before the line 3, and line 2 before the line 4 (and of course line 3 before line 4). Standard does not say more and indeed you can expect different results with different C++ compilers.

                  这篇关于运算符<<中的执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
                  How should a size-limited stl-like container be implemented?(应该如何实现大小受限的 stl 类容器?)
                  Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
                  STL BigInt class implementation(STL BigInt 类实现)
                  Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
                  Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
                  <legend id='oqM5J'><style id='oqM5J'><dir id='oqM5J'><q id='oqM5J'></q></dir></style></legend>

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

                        • <small id='oqM5J'></small><noframes id='oqM5J'>

                        • <tfoot id='oqM5J'></tfoot>