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

    <small id='9LAqC'></small><noframes id='9LAqC'>

      1. <tfoot id='9LAqC'></tfoot>
          <bdo id='9LAqC'></bdo><ul id='9LAqC'></ul>

      2. 重载括号运算符 [] 以获取和设置

        时间:2023-10-06
        <tfoot id='nbgWs'></tfoot>

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

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

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

              • <bdo id='nbgWs'></bdo><ul id='nbgWs'></ul>
                1. 本文介绍了重载括号运算符 [] 以获取和设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有以下课程:

                  class risc { // singleton
                      protected:
                          static unsigned long registers[8];
                  
                      public:
                          unsigned long operator [](int i)
                          {
                              return registers[i];
                          }
                  };
                  

                  如您所见,我已经为获取"实现了方括号运算符.
                  现在我想实现它进行设置,即:risc[1] = 2.

                  as you can see I've implemented the square brackets operator for "getting".
                  Now I would like to implement it for setting, i.e.: risc[1] = 2.

                  怎么做?

                  推荐答案

                  试试这个:

                  class risc { // singleton
                  protected:
                      static unsigned long registers[8];
                  
                  public:
                      unsigned long operator [](int i) const    {return registers[i];}
                      unsigned long & operator [](int i) {return registers[i];}
                  };
                  

                  这篇关于重载括号运算符 [] 以获取和设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:以允许响应更新的方式重载 C++ 索引下标运算符 下一篇:为什么 C++ STL 不提供任何“树"?容器?

                  相关文章

                  最新文章

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

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

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