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

  • <small id='5UicM'></small><noframes id='5UicM'>

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

        在 dll 接口中使用 stl 類時消除 C4251 警告的一種方

        One way of eliminating C4251 warning when using stl-classes in the dll-interface(在 dll 接口中使用 stl 類時消除 C4251 警告的一種方法)
          <tfoot id='bDPEn'></tfoot>
        1. <legend id='bDPEn'><style id='bDPEn'><dir id='bDPEn'><q id='bDPEn'></q></dir></style></legend>
        2. <i id='bDPEn'><tr id='bDPEn'><dt id='bDPEn'><q id='bDPEn'><span id='bDPEn'><b id='bDPEn'><form id='bDPEn'><ins id='bDPEn'></ins><ul id='bDPEn'></ul><sub id='bDPEn'></sub></form><legend id='bDPEn'></legend><bdo id='bDPEn'><pre id='bDPEn'><center id='bDPEn'></center></pre></bdo></b><th id='bDPEn'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='bDPEn'><tfoot id='bDPEn'></tfoot><dl id='bDPEn'><fieldset id='bDPEn'></fieldset></dl></div>
              <tbody id='bDPEn'></tbody>

              • <small id='bDPEn'></small><noframes id='bDPEn'>

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

                  本文介紹了在 dll 接口中使用 stl 類時消除 C4251 警告的一種方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  在 dll 接口中使用 stl 類不是一個好習慣,如 處理警告 c4251 的常見做法:class ...需要有 dll-interface 解釋.給出一個例子:

                  #include #include <字符串>#include <向量>類 __declspec(dllexport) HelloWorld{上市:你好世界(){abc.resize(5);for(int i=0; i<5; i++)abc[i] = i*10;str="你好世界";}?你好世界(){}std::vectorABC;std::string str;};

                  編譯此文件時,可以觀察到以下警告:

                   警告 C4251: 'HelloWorld::str' : class 'std::basic_string<_Elem,_Traits,_Ax>'需要有 dll 接口供HelloWorld"類的客戶端使用警告 C4251:HelloWorld::abc":類std::vector<_Ty>"需要有 dll 接口供HelloWorld"類的客戶端使用

                  那么問題是我們如何在不使用 STL 類向量和字符串的情況下實現相同的功能.我能想到的一種實現如下:

                  class __declspec(dllexport) HelloWorld2{上市:你好世界2(){abc_len = 5;p_abc = new int [abc_len];for(int i=0; i<abc_len; i++)p_abc[i] = i*10;std::string temp_str("hello_the_world");str_len = temp_str.size();p_str = 新字符[str_len+1];strcpy(p_str,temp_str.c_str());}~HelloWorld2(){刪除 []p_abc;刪除 []p_str;}int *p_abc;國際 abc_len;字符 *p_str;int str_len;};

                  如您所見,在新的實現中,我們使用 int *p_abc 替換向量 abc 和 char *p_str 替換字符串 str.我的問題是是否有其他優雅的實現方法可以做到這一點.謝謝!

                  解決方案

                  我認為您至少有 5 種可能的選擇來解決這個問題:

                  1. 您仍然可以為您的字段保留 STL/模板類,也可以將它們用作參數類型,只要您將所有字段保持為私有(無論如何這都是一個很好的做法).這里是關于這個的討論.要刪除警告,您可以簡單地根據 #pragma 語句使用.

                  2. 您可以創建帶有私有 STL 字段的小型包裝類,并將您的包裝類類型的字段公開給公眾,但這很可能只會將警告移到其他地方.

                  3. 您可以使用 PIMPL 習語來隱藏您的私有實現類中的 STL 字段,它甚至不會從您的庫中導出,也不會在庫外可見.

                  4. 或者您實際上可以按照 C4251 警告中的建議,以此處.簡而言之,您必須在 HelloWorld 類之前插入以下代碼行:

                    <代碼>...#include <向量>模板類 __declspec(dllexport) std::allocator;模板類 __declspec(dllexport) std::vector;模板類 __declspec(dllexport) std::string;類 __declspec(dllexport) HelloWorld...

                    順便說一下,這些導出的順序似乎很重要:向量類模板在內部使用分配器類模板,因此必須在向量實例化之前導出分配器實例化.p>

                  5. 直接使用內部函數可能是您最糟糕的選擇,但如果您封裝字段

                    int *p_abc;國際 abc_len;

                    在類似class MyFancyDataArray 和字段

                    char *p_str;int str_len;

                    在類似 class MyFancyString 的東西中,那么這將是一個更體面的解決方案(類似于第二點描述的解決方案).但過于頻繁地重新發明輪子可能不是最好的習慣.

                  It is not a good practice using stl-classes in the dll-interface as Common practice in dealing with warning c4251: class … needs to have dll-interface explains. An example is given:

                  #include <iostream>
                  #include <string>
                  #include <vector>
                  
                  
                  class __declspec(dllexport) HelloWorld
                  {
                  public:
                      HelloWorld()
                      {
                          abc.resize(5);
                          for(int i=0; i<5; i++)
                              abc[i] = i*10;
                  
                          str="hello the world";
                      }
                      ~HelloWorld()
                      {
                  
                      }
                  
                      std::vector<int> abc;
                      std::string str;
                  
                  };
                  

                  When compiling this file, the following warnings can be observed:

                   warning C4251: 'HelloWorld::str' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'HelloWorld'    
                   warning C4251: 'HelloWorld::abc' : class 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class 'HelloWorld'
                  

                  Then the question is how we can implement the same functionality without using STL class vector and string. One implementation I could think of is as follows:

                  class __declspec(dllexport) HelloWorld2
                  {
                  public:
                      HelloWorld2()
                      {
                           abc_len = 5;
                           p_abc = new int [abc_len];
                           for(int i=0; i<abc_len; i++)
                               p_abc[i] = i*10;
                  
                           std::string temp_str("hello_the_world");
                           str_len = temp_str.size();
                           p_str = new char[str_len+1];
                           strcpy(p_str,temp_str.c_str());
                      }
                      ~HelloWorld2()
                      {
                          delete []p_abc;
                          delete []p_str;
                      }
                  
                      int *p_abc;
                      int abc_len;
                      char *p_str;
                      int str_len;
                  
                  
                  
                  };
                  

                  As you can see, in the new implementation we use int *p_abc to substitute vector abc and char *p_str to replace string str. The question I have is whether there are other elegant implementation approaches that can do the same. Thanks!

                  解決方案

                  I think you've got at least 5 possible options to solve this problem:

                  1. You could still keep STL/template classes for your fields and also use them as parameter types, as long as you keep all the fields private (which is a good practice anyway). Here is a discussion about this. To remove the warnings you could simply use according #pragma statements.

                  2. You could create small wrapper classes with private STL fields and expose fields of your wrapper class types to the public instead, but this would most probably only move the warnings to another places.

                  3. You could use the PIMPL idiom to hide your STL fields in a private implementation class, which will not even be exported from your library nor be visible outside of it.

                  4. Or you could actually export all the required template class specializations, as suggested in the C4251 warning, in a way that is described here. In short you would have to insert following lines of code before your HelloWorld class:

                    ...
                    #include <vector>
                    
                    template class __declspec(dllexport) std::allocator<int>;
                    template class __declspec(dllexport) std::vector<int>;
                    template class __declspec(dllexport) std::string;
                    
                    class __declspec(dllexport) HelloWorld
                    ...
                    

                    By the way, the order of those exports seems to be important: the vector class template uses the allocator class template internally, so the allocator instantiation has to be exported before the vector instantiation.

                  5. The direct use of intrinsics is probably your worst option, but if you encapsulate your fields

                    int *p_abc;
                    int abc_len;
                    

                    in something like class MyFancyDataArray and the fields

                    char *p_str;
                    int str_len;
                    

                    in something like class MyFancyString, then this would be a more decent solution (similar to the one described at the second point). But it is probably not the best habit to reinvent the wheel too often.

                  這篇關于在 dll 接口中使用 stl 類時消除 C4251 警告的一種方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 不能)
                    1. <tfoot id='QZxnz'></tfoot>
                          <tbody id='QZxnz'></tbody>

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

                        • <small id='QZxnz'></small><noframes id='QZxnz'>

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

                            主站蜘蛛池模板: 91av视频在线播放 | 欧美日韩不卡 | 91精品国产综合久久久亚洲 | www.亚洲免费 | 亚洲福利精品 | 国产一区999 | 日韩在线日韩 | 日本精品视频在线观看 | 黄色一级视频免费 | 三区在线观看 | 污视频在线免费观看 | 日韩在线视频免费观看 | 久久久青草婷婷精品综合日韩 | 亚洲精品一区二区三区四区高清 | 国产精品福利在线观看 | 黄色永久免费 | 黄色片在线网站 | 成人在线观看亚洲 | 亚洲一区二区视频 | 欧美一区二区在线播放 | 2019精品手机国产品在线 | 三级免费毛片 | 91麻豆蜜桃一区二区三区 | 国产乱码高清区二区三区在线 | 久久天堂| 久久久综合色 | 日韩二区| 久久精品国产99国产 | 日韩欧美中文字幕在线视频 | 久久久久久亚洲精品 | 999视频 | 在线观看精品视频网站 | 成人国产精品色哟哟 | 成年人在线观看视频 | 国产精品美女久久久久久久网站 | 日韩电影中文字幕 | 97av视频| 久久精品国产久精国产 | 久久久国产一区 | 男女激情网站免费 | 精品欧美一区二区三区久久久 |