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

<tfoot id='ms8Uo'></tfoot>
  • <small id='ms8Uo'></small><noframes id='ms8Uo'>

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

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

        C++:友元聲明‘聲明一個非模板函數

        C++ : friend declaration ‘declares a non-template function(C++:友元聲明‘聲明一個非模板函數)
            <tbody id='KmkFr'></tbody>
          1. <small id='KmkFr'></small><noframes id='KmkFr'>

            <tfoot id='KmkFr'></tfoot>

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

                1. <legend id='KmkFr'><style id='KmkFr'><dir id='KmkFr'><q id='KmkFr'></q></dir></style></legend>
                  本文介紹了C++:友元聲明‘聲明一個非模板函數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我遇到了重載 << 流運算符的問題,但我沒有找到解決方案:

                  I have a problem to overload the << stream operator and I don't find the solution :

                  template<class T, unsigned int TN>
                  class NVector
                  {
                      inline friend std::ostream& operator<< (
                          std::ostream &lhs, const NVector<T, TN> &rhs);
                  };
                  
                  template<class T, unsigned int TN>
                  inline std::ostream& NVector<T, TN>::operator<<(
                      std::ostream &lhs, const NVector<T, TN> &rhs)
                  {
                      /* SOMETHING */
                      return lhs;
                  };
                  

                  它產生以下錯誤消息:

                  警告:朋友聲明‘std::ostream&operator<<(std::ostream&, const NVector&)' 聲明了一個非模板函數[-Wnon-template-friend]

                  warning : friend declaration ‘std::ostream& operator<<(std::ostream&, const NVector&)’ declares a non-template function [-Wnon-template-friend]

                  錯誤:'std::ostream&NVector::operator<<(std::ostream&, const NVector&)' 必須只取一個參數

                  error: ‘std::ostream& NVector::operator<<(std::ostream&, const NVector&)’ must take exactly one argument

                  如何解決這個問題?

                  非常感謝.

                  推薦答案

                  在你的代碼中有兩個不同的問題,第一個是 friend 聲明(正如警告明確說的,也許不是這樣清晰易懂)將單個非模板化函數聲明為友元.也就是說,當您實例化模板 NVector 時,它聲明了一個非模板化函數 std::ostream&operator<<(std::ostream&,NVector) 作為朋友.請注意,這與聲明您作為朋友提供的模板函數不同.

                  There are two different issues in your code, the first is that the friend declaration (as the warning clearly says, maybe not so clear to understand) declares a single non-templated function as a friend. That is, when you instantiate the template NVector<int,5> it declares a non-templated function std::ostream& operator<<(std::ostream&,NVector<int,5>) as a friend. Note that this is different from declaring the template function that you provided as a friend.

                  我建議您在類定義中定義友元函數.您可以在此答案中閱讀更多相關信息.

                  I would recommend that you define the friend function inside the class definition. You can read more on this in this answer.

                  template <typename T, unsigned int TN>
                  class NVector {
                     friend std::ostream& operator<<( std::ostream& o, NVector const & v ) {
                        // code goes here
                        return o;
                     }
                  };
                  

                  或者,您可以選擇其他選項:

                  Alternatively you can opt for other options:

                  1. operator<< 模板聲明為朋友(將授予對模板的任何和所有實例的訪問權限),
                  2. 將該模板的特定實例聲明為朋友(編寫起來更麻煩)或
                  3. 完全避免友誼提供公共print(std::ostream&)成員函數并從非友元模板operator<<調用它.我仍然會選擇與非模板函數交朋友,并在模板化類中提供定義.
                  1. declare the operator<< template as a friend (will grant access to any and all instantiations of the template),
                  2. declare a particular instantiation of that template as a friend (more cumbersome to write) or
                  3. avoid friendship altogether providing a public print( std::ostream& ) member function and calling it from a non-friend templated operator<<. I would still opt to befriend the non-template function an provide the definition inside the templated class.

                  第二個問題是,當您想在左側參數的類之外定義一個運算符時,該運算符是一個自由函數(未綁定到類),因此它應該不合格:

                  The second issue is that when you want to define an operator outside of the class of the left hand side argument, the operator is a free function (not bound to a class) and thus it should not be qualified:

                  template<class T, unsigned int TN>
                  inline std::ostream& operator<<(std::ostream &lhs, const NVector<T, TN> &rhs)
                  {
                      /* SOMETHING */
                      return lhs;
                  };
                  

                  這篇關于C++:友元聲明‘聲明一個非模板函數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 不能)
                  <tfoot id='FmCCH'></tfoot>
                  <i id='FmCCH'><tr id='FmCCH'><dt id='FmCCH'><q id='FmCCH'><span id='FmCCH'><b id='FmCCH'><form id='FmCCH'><ins id='FmCCH'></ins><ul id='FmCCH'></ul><sub id='FmCCH'></sub></form><legend id='FmCCH'></legend><bdo id='FmCCH'><pre id='FmCCH'><center id='FmCCH'></center></pre></bdo></b><th id='FmCCH'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='FmCCH'><tfoot id='FmCCH'></tfoot><dl id='FmCCH'><fieldset id='FmCCH'></fieldset></dl></div>
                  <legend id='FmCCH'><style id='FmCCH'><dir id='FmCCH'><q id='FmCCH'></q></dir></style></legend>
                  • <small id='FmCCH'></small><noframes id='FmCCH'>

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

                            主站蜘蛛池模板: 日韩和的一区二在线 | 伊人伊人伊人 | 国产免费xxx | 久久国产高清 | 色婷婷国产精品综合在线观看 | 91极品视频 | 成人免费在线播放视频 | 欧美日在线| 99精品久久久久久 | 国产高清视频一区二区 | 自拍偷拍亚洲一区 | 情侣酒店偷拍一区二区在线播放 | 久草资源在线 | 综合色在线 | 天堂亚洲网| 日韩一区在线播放 | 91国产在线视频在线 | 久热9| 中文字幕亚洲欧美 | 国产精品一区二区av | 羞羞的视频在线观看 | 欧美综合久久 | 国产精品久久久av | 成人av一区 | 国产在线观看网站 | 精品国产不卡一区二区三区 | 91最新在线视频 | 99精品网| 日韩成人免费视频 | 黄a网站 | 日本激情视频网 | 综合久久av | 免费一二区 | av网站在线免费观看 | 日韩国产精品一区二区三区 | 在线观看av网站永久 | 91大神新作在线观看 | 欧美黄在线观看 | 美日韩视频 | 欧美日韩亚洲一区 | 亚洲视频手机在线 |