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

<legend id='ZjyDx'><style id='ZjyDx'><dir id='ZjyDx'><q id='ZjyDx'></q></dir></style></legend>
    <bdo id='ZjyDx'></bdo><ul id='ZjyDx'></ul>

      <tfoot id='ZjyDx'></tfoot>

      1. <i id='ZjyDx'><tr id='ZjyDx'><dt id='ZjyDx'><q id='ZjyDx'><span id='ZjyDx'><b id='ZjyDx'><form id='ZjyDx'><ins id='ZjyDx'></ins><ul id='ZjyDx'></ul><sub id='ZjyDx'></sub></form><legend id='ZjyDx'></legend><bdo id='ZjyDx'><pre id='ZjyDx'><center id='ZjyDx'></center></pre></bdo></b><th id='ZjyDx'></th></span></q></dt></tr></i><div id='ZjyDx'><tfoot id='ZjyDx'></tfoot><dl id='ZjyDx'><fieldset id='ZjyDx'></fieldset></dl></div>
      2. dllimport静态数据成员的C++定义

        时间:2023-08-28
          <i id='5aohH'><tr id='5aohH'><dt id='5aohH'><q id='5aohH'><span id='5aohH'><b id='5aohH'><form id='5aohH'><ins id='5aohH'></ins><ul id='5aohH'></ul><sub id='5aohH'></sub></form><legend id='5aohH'></legend><bdo id='5aohH'><pre id='5aohH'><center id='5aohH'></center></pre></bdo></b><th id='5aohH'></th></span></q></dt></tr></i><div id='5aohH'><tfoot id='5aohH'></tfoot><dl id='5aohH'><fieldset id='5aohH'></fieldset></dl></div>
            <bdo id='5aohH'></bdo><ul id='5aohH'></ul>
            1. <tfoot id='5aohH'></tfoot>

              • <legend id='5aohH'><style id='5aohH'><dir id='5aohH'><q id='5aohH'></q></dir></style></legend>
                    <tbody id='5aohH'></tbody>

                  <small id='5aohH'></small><noframes id='5aohH'>

                  本文介绍了dllimport静态数据成员的C++定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我确实有一个如下所示的类:

                  I do have a class which looks like below:

                  //.h file
                  class __declspec(dllimport) MyClass
                  {
                      public:
                      //stuff
                      private:
                  
                      static int myInt;
                  };
                  
                  // .cpp file
                  int MyClass::myInt = 0;
                  

                  我收到以下编译错误:

                  error C2491: 'MyClass::myInt' : definition of dllimport static data member not allowed
                  

                  我该怎么办?

                  推荐答案

                  __declspec(dllimport) 表示当前代码正在使用实现您的类的 DLL.成员函数和静态数据成员因此在 DLL 中定义,并且在您的程序中再次定义它们是错误的.

                  __declspec(dllimport) means that the current code is using the DLL that implements your class. The member functions and static data members are thus defined in the DLL, and defining them again in your program is an error.

                  如果您尝试为实现此类的 DLL 编写代码(从而定义成员函数和静态数据成员),那么您需要改为标记类 __declspec(dllexport).

                  If you are trying to write the code for the DLL that implements this class (and thus defines the member functions and static data members) then you need to mark the class __declspec(dllexport) instead.

                  为此使用宏是很常见的.在构建 DLL 时,您定义一个宏 BUILDING_MYDLL 或类似的.在 MyClass 的标题中,你有:

                  It is common to use a macro for this. When building your DLL you define a macro BUILDING_MYDLL or similar. In your header for MyClass you then have:

                      #ifdef _MSC_VER
                      #  ifdef BUILDING_MYDLL
                      #    define MYCLASS_DECLSPEC __declspec(dllexport)
                      #  else
                      #    define MYCLASS_DECLSPEC __declspec(dllimport)
                      #  endif
                      #endif
                  
                      class MYCLASS_DECLSPEC MyClass
                      {
                          ...
                      };
                  

                  这意味着您可以在 DLL 和使用该 DLL 的应用程序之间共享标头.

                  This means that you can share the header between the DLL and the application that uses the DLL.

                  这篇关于dllimport静态数据成员的C++定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 VS 中编译 C++,而无需在运行时使用 MSVCP120D.dll 下一篇:将 .dll 导入 Qt

                  相关文章

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

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

                • <tfoot id='BieNi'></tfoot>

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