久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

      <legend id='w8vn4'><style id='w8vn4'><dir id='w8vn4'><q id='w8vn4'></q></dir></style></legend>
      <tfoot id='w8vn4'></tfoot>
      • <bdo id='w8vn4'></bdo><ul id='w8vn4'></ul>

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

      1. 是否有可能使函數接受給定參數的多種數據類型

        is it possible to make function that will accept multiple data types for given argument?(是否有可能使函數接受給定參數的多種數據類型?)
        1. <legend id='kK1xk'><style id='kK1xk'><dir id='kK1xk'><q id='kK1xk'></q></dir></style></legend>
            <tbody id='kK1xk'></tbody>

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

                <tfoot id='kK1xk'></tfoot>

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

                • 本文介紹了是否有可能使函數接受給定參數的多種數據類型?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  編寫函數時,我必須像這樣聲明輸入和輸出數據類型:

                  Writing a function I must declare input and output data types like this:

                  int my_function (int argument) {}
                  

                  是否可以聲明我的函數接受 int、bool 或 char 類型的變量,并且可以輸出這些數據類型?

                  Is it possible to make such a declaration that my function would accept variable of type int, bool or char, and can output these data types ?

                  //non working example
                  [int bool char] my_function ([int bool char] argument) {}
                  

                  推薦答案

                  您的選擇是

                  備選方案 1

                  您可以使用模板

                  template <typename T> 
                  T myfunction( T t )
                  {
                      return t + t;
                  }
                  

                  備選方案 2

                  普通函數重載

                  bool myfunction(bool b )
                  {
                  }
                  
                  int myfunction(int i )
                  {
                  }
                  

                  您為您期望的每個參數的每種類型提供不同的函數.您可以混合使用替代方案 1.編譯器會為您選擇合適的方案.

                  You provide a different function for each type of each argument you expect. You can mix it Alternative 1. The compiler will the right one for you.

                  替代方案 3

                  你可以使用聯合

                  union myunion
                  { 
                      int i;
                      char c;
                      bool b;
                  };
                  
                  myunion my_function( myunion u ) 
                  {
                  }
                  

                  替代方案 4

                  你可以使用多態.對于 int 、 char 、 bool 可能有點矯枉過正,但對于更復雜的類類型很有用.

                  You can use polymorphism. Might be an overkill for int , char , bool but useful for more complex class types.

                  class BaseType
                  {
                  public:
                      virtual BaseType*  myfunction() = 0;
                      virtual ~BaseType() {}
                  };
                  
                  class IntType : public BaseType
                  {
                      int X;
                      BaseType*  myfunction();
                  };
                  
                  class BoolType  : public BaseType
                  {
                      bool b;
                      BaseType*  myfunction();
                  };
                  
                  class CharType : public BaseType
                  {
                      char c;
                      BaseType*  myfunction();
                  };
                  
                  BaseType*  myfunction(BaseType* b)
                  {
                      //will do the right thing based on the type of b
                      return b->myfunction();
                  }
                  

                  這篇關于是否有可能使函數接受給定參數的多種數據類型?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Why do two functions have the same address?(為什么兩個函數的地址相同?)
                  Why the initializer of std::function has to be CopyConstructible?(為什么 std::function 的初始化程序必須是可復制構造的?)
                  mixing templates with polymorphism(混合模板與多態性)
                  When should I use the keyword quot;typenamequot; when using templates(我什么時候應該使用關鍵字“typename?使用模板時)
                  Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標準庫)
                  gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數模板,而 clang 不能)

                      <tbody id='2aTOX'></tbody>
                    • <bdo id='2aTOX'></bdo><ul id='2aTOX'></ul>
                      <legend id='2aTOX'><style id='2aTOX'><dir id='2aTOX'><q id='2aTOX'></q></dir></style></legend>
                      • <tfoot id='2aTOX'></tfoot>

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

                            <small id='2aTOX'></small><noframes id='2aTOX'>

                          1. 主站蜘蛛池模板: 国产精品性做久久久久久 | 69堂永久69tangcom | 欧美激情精品久久久久久变态 | 久久国产精品一区二区三区 | 免费99精品国产自在在线 | wwww.xxxx免费 | 国产情品 | 色成人免费网站 | 中文字幕在线剧情 | 日韩欧美一级精品久久 | 精品国产一区二区三区久久久蜜月 | 欧美久久久久 | 国产精品波多野结衣 | 天天干天天爱天天爽 | 日本久久精品视频 | 久久精品国产亚洲一区二区 | 18av在线播放 | 日韩视频1| 亚洲啊v在线 | 免费在线成人网 | 一区二区三区欧美 | 精品国产乱码久久久久久闺蜜 | 九九在线视频 | www.天天干.com | 国产超碰人人爽人人做人人爱 | 国产男女猛烈无遮掩视频免费网站 | 国产高清视频一区 | 久久91| 狠狠干美女| 日韩精品一区二区三区中文在线 | 欧美电影网 | 国产一区二区三区四 | 91视频久久 | 日韩小视频 | 黄视频网址 | 久久久久久久久久久久久久av | 狠狠热视频 | 五月天激情电影 | 国产精品三级久久久久久电影 | 欧美精品一区二区三区蜜桃视频 | 日日骚网 |