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

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

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

        为什么我不能使用“中断"?C++ 中三元条件语句

        时间:2023-10-07
          <bdo id='ub0ns'></bdo><ul id='ub0ns'></ul>

            <tbody id='ub0ns'></tbody>
          <legend id='ub0ns'><style id='ub0ns'><dir id='ub0ns'><q id='ub0ns'></q></dir></style></legend>

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

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

                • 本文介绍了为什么我不能使用“中断"?C++ 中三元条件语句中的语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  Node 是一个非常简单的类,只有一个构造函数和几个变量:一个名称"(实际上只是一个字符)和两个称为左"和右"的子节点指针.

                  Node is a very simple class with a just a constructor and a few variables: a "name" (actually just a char) and two child Node pointers called "left" and "right".

                  我刚开始写一些需要放到最左边节点的代码,当我想到这个时我很高兴:

                  I was just starting to write some code that needs to drop to the left-most node, and I was quite pleased when I came up with this:

                  Node *current = this->root;
                  while (true) (current->left != nullptr) ? current = current->left : break;
                  

                  看起来很简单:在一个无限循环中,检查 current 是否有左孩子,如果有,则将 current 设置为那个左孩子,如果没有,则跳出循环.这是一个很酷的小单线,不太难读.(我评论了!)

                  Seems simple enough: in an infinite loop, check to see if current has a left child, if so, set current to that left child, if not, break out of the loop. It's a cool little one-liner, not too unreadable. (And I commented it!)

                  好吧,我的编译器不喜欢它:

                  Well, my compiler doesn't like it:

                  iterator.cpp:20:70: error: expected expression
                      while (true) (current->left != nullptr) ? current = current->left : break;
                                                                                          ^
                  1 error generated.
                  

                  此外,仅在 while 循环中加入一些大括号并将三元运算符移动到它自己的行也无济于事(不出所料).我不得不把它变成一个 if/else 以便编译器接受它.

                  Also, just throwing some braces into the while loop and moving the ternary operator to it's own line didn't help (unsurprisingly). I had to turn it into an if/else for the compiler to accept it.

                  有人能解释一下它是如何解释单行的以及它为什么反对吗?

                  Can someone explain how it's interpreting the one-liner and why it objects?

                  推荐答案

                  三元条件运算符是一种将多个表达式组合成一个更大表达式的运算符.break 是一个语句而不是一个表达式,所以它不能在三元条件表达式中使用.

                  The ternary conditional operator is an operator that combines multiple expressions into a larger expression. break is a statement and not an expression, so it can't be used inside a ternary conditional expression.

                  不过,您可以像这样重写代码:

                  You could, though, rewrite your code like this:

                  while (current->left != nullptr) current = current->left;
                  

                  希望这有帮助!

                  这篇关于为什么我不能使用“中断"?C++ 中三元条件语句中的语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:C/C+ 程序的最大堆栈大小? 下一篇:在 C++ 中使用带密钥更新的最小优先级队列的最简

                  相关文章

                  最新文章

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

                    1. <small id='qvuLB'></small><noframes id='qvuLB'>

                    2. <legend id='qvuLB'><style id='qvuLB'><dir id='qvuLB'><q id='qvuLB'></q></dir></style></legend>
                        <bdo id='qvuLB'></bdo><ul id='qvuLB'></ul>