• <legend id='W9jGE'><style id='W9jGE'><dir id='W9jGE'><q id='W9jGE'></q></dir></style></legend>

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

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

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

      1. Postfix运算符重载中虚拟参数的目的?C++

        Purpose of Dummy Parameter in Postfix Operator Overload? c++(Postfix运算符重载中虚拟参数的目的?C++)

          <tfoot id='A8bNf'></tfoot>

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

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

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

              <tbody id='A8bNf'></tbody>
              <bdo id='A8bNf'></bdo><ul id='A8bNf'></ul>

                1. 本文介绍了Postfix运算符重载中虚拟参数的目的?C++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当重载后缀运算符时,我可以做一些简单的事情

                  When overloading the postfix operator, I can do something simple like

                  Class Foo
                  {
                  private: 
                     int someBS;
                  public:
                     //declaration of  pre &postfix++
                     Foo operator++();
                     //rest of class not shown
                  };
                  

                  Prefix 不需要带任何参数,所以当我定义它时,就像

                  Prefix doesn't need to take any parameters, so when I define it, something like

                  Foo Foo::operator()
                  {
                     someBS ++;
                     return *this;
                  }
                  

                  这对我来说很有意义.

                  当我去定义后缀重载时,我必须包含一个虚拟的 int 参数

                  When I go to define the postfix overload I have to include a dummy int parameter

                  Foo Foo::operator++(int)
                  {
                     Foo temp = *this;
                     someBS ++;
                     return temp;
                  }
                  

                  我的问题是为什么?我从来没有在方法中使用它.前缀运算符不需要一个.返回 temp 值的后缀不依赖于虚拟参数.我知道如果我想要重载一个后缀操作符就是这样,我只想知道背后的原因.

                  My question is why? I don't ever use it in the method. The prefix operator doesn't require one. The postfix returning the temp value is not dependent on the dummy parameter. I know that if I want to overload a postfix operator that's how it's done, I just want to know the reason behind.

                  推荐答案

                  虚拟参数只是为了区分后缀和前缀运算符.在这两种情况下,名称 ++-- 是相同的,因此必须有some 方法来指定您要定义的那个.添加一个虚拟参数可能并不优雅,但任何替代方案都可能需要发明新的语法(可能是一个 postfix 关键字,这会破坏使用 postfix 作为标识符的代码).

                  The dummy parameter is simply there to distinguish between the postfix and prefix operators. The name ++ or -- is the same in both cases, so there has to be some way to specify which one you're defining. Adding a dummy parameter is perhaps not elegant, but any alternatives would probably have required inventing new syntax (perhaps a postfix keyword, which would break code that uses postfix as an identifier).

                  这篇关于Postfix运算符重载中虚拟参数的目的?C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How to print vector#39;s data(如何打印矢量的数据)
                  Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  MSVC++ warning flags(MSVC++ 警告标志)
                  How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                  stack overflow error in C++ program(C++程序中的堆栈溢出错误)
                      <tbody id='UUzrX'></tbody>
                    <i id='UUzrX'><tr id='UUzrX'><dt id='UUzrX'><q id='UUzrX'><span id='UUzrX'><b id='UUzrX'><form id='UUzrX'><ins id='UUzrX'></ins><ul id='UUzrX'></ul><sub id='UUzrX'></sub></form><legend id='UUzrX'></legend><bdo id='UUzrX'><pre id='UUzrX'><center id='UUzrX'></center></pre></bdo></b><th id='UUzrX'></th></span></q></dt></tr></i><div id='UUzrX'><tfoot id='UUzrX'></tfoot><dl id='UUzrX'><fieldset id='UUzrX'></fieldset></dl></div>

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

                            <bdo id='UUzrX'></bdo><ul id='UUzrX'></ul>