久久久久久久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 警告的一種方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時送ChatGPT賬號..

                  在 dll 接口中使用 stl 類不是一個好習(xí)慣,如 處理警告 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"類的客戶端使用

                  那么問題是我們?nèi)绾卧诓皇褂?STL 類向量和字符串的情況下實現(xiàn)相同的功能.我能想到的一種實現(xiàn)如下:

                  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;};

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

                  解決方案

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

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

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

                  3. 您可以使用 PIMPL 習(xí)語來隱藏您的私有實現(xiàn)類中的 STL 字段,它甚至不會從您的庫中導(dǎo)出,也不會在庫外可見.

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

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

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

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

                    int *p_abc;國際 abc_len;

                    在類似class MyFancyDataArray 和字段

                    char *p_str;int str_len;

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

                  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.

                  這篇關(guān)于在 dll 接口中使用 stl 類時消除 C4251 警告的一種方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Why do two functions have the same address?(為什么兩個函數(shù)的地址相同?)
                  Why the initializer of std::function has to be CopyConstructible?(為什么 std::function 的初始化程序必須是可復(fù)制構(gòu)造的?)
                  mixing templates with polymorphism(混合模板與多態(tài)性)
                  When should I use the keyword quot;typenamequot; when using templates(我什么時候應(yīng)該使用關(guān)鍵字“typename?使用模板時)
                  Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標(biāo)準(zhǔn)庫)
                  gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數(shù)模板,而 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>

                            主站蜘蛛池模板: 在线免费观看av网站 | 日本黄色免费网站 | 日韩专区在线 | 秋霞午夜鲁丝一区二区老狼 | 福利片在线观看 | 伦一理一级一a一片 | 亚洲一区高清 | 在线看片你懂的 | 久久综合爱 | 黄色高潮视频 | 亚洲综合视频在线观看 | 丁香婷婷色 | 国产黄在线观看 | 欧美 日韩 国产 成人 在线 | 一级免费黄色片 | av一二三区 | 最新免费黄色网址 | 超碰中文字幕 | 欧美日韩国产成人 | 国产一级特黄aaa大片 | 免费看大片a | 精久久久 | 麻豆av片| 91麻豆精品国产91久久久久久久久 | 国产资源在线观看 | 欧美日韩啪啪 | 激情综合久久 | 波多野结衣视频在线播放 | 久久精品视频网站 | 成人夜色| 成人免费网站黄 | 九九九精品视频 | 97视频在线观看免费 | 艳妇臀荡乳欲伦交换h漫 | 欧美在线激情 | 国产午夜一区二区 | 中文字幕在线视频播放 | 在线观看免费毛片 | 美女黄色在线观看 | 久久av资源 | 亚洲激情一区二区 |