我有一个包含std :: map变量的类。我需要通过DLL导出 类。该课程看起来像这样: class MyClass { public: MyClass( ); MyClass(const MyClass&); private: MyClass& operator =(const MyClass&); typedef std :: map< SomeKey,SomethingElseTreasureChest; TreasureChest m_treasures; };
I have a class that contains a std::map variable. I need to export the class via a DLL. the class looks something like this: class MyClass { public: MyClass(); MyClass(const MyClass&); private: MyClass& operator=(const MyClass&); typedef std::map<SomeKey, SomethingElseTreasureChest ; TreasureChest m_treasures; };
推荐答案你可以__declspec(dllexport)你想要的每个类成员 导出,或__declspec(dllexport)类定义。 在dll用户中您应该使用 __declspec(dllimport)声明该类的代码。有一些标准方法可以使用 宏来完成。参见 www.codeproject/dll/SimpleDll2 .asp 或 msdn2.microsoft/en-US/lib...4d(VS.80).aspx 再见 QbProg you can either __declspec(dllexport) every member of the class that you want to export, or __declspec(dllexport) the class definition. In the "dll user" code you should declare the class with __declspec(dllimport). There are standard ways to do that using macros. See www.codeproject/dll/SimpleDll2.asp or msdn2.microsoft/en-US/lib...4d(VS.80).aspx Good Bye QbProg
QbProg写道: QbProg wrote: 你可以__declspec(dllexport)你要导出的每个类的成员,或者__declspec(dllexport)这个类定义。 在dll用户中您应该使用 __declspec(dllimport)声明该类的代码。有一些标准方法可以使用 宏来完成。参见 www.codeproject/dll/SimpleDll2 .asp 或 msdn2.microsoft/en-US/lib...4d(VS.80).aspx 再见 QbProg you can either __declspec(dllexport) every member of the class that you want to export, or __declspec(dllexport) the class definition. In the "dll user" code you should declare the class with __declspec(dllimport). There are standard ways to do that using macros. See www.codeproject/dll/SimpleDll2.asp or msdn2.microsoft/en-US/lib...4d(VS.80).aspx Good Bye QbProg
参见: support.microsoft/kb/168958 相关文字:唯一的STL目前可以导出的容器是 vector。所有其他容器(即map,set,queue,list,deque) 都包含嵌套类,无法导出。 文章是最后一篇2005年9月回顾 - 我想知道它是否现在可以从DLL导出std :: map
See: support.microsoft/kb/168958 Relevant text: The only STL container that can currently be exported is vector. The other containers (that is, map, set, queue, list, deque) all contain nested classes and cannot be exported. The article was last reviewed in September 2005 - I wanted to know if it is now possible to export std::map from a DLL
灰色外星人 < gr ** @ andromeda写信息 新闻:uY ********************* @ bt ... "Grey Alien" <gr**@andromedawrote in message news:uY*********************@bt... >我有一个包含std :: map变量的类。我需要通过DLL导出类。这个类看起来像这样: >I have a class that contains a std::map variable. I need to export theclass via a DLL. the class looks something like this:
不,你不是。创建一个接口(具有纯虚拟指针的类), 从中派生实现,并仅共享该接口。你可以通过将接口定义放在公共头文件中来实现。不需要 __declspec(dllexport)语句。 导出C ++类是个坏消息。 __declspec(dllexport)应该是 仅用于''extern''C"''函数。
No you don''t. Create an interface (class with pure virtual pointers), derive the implementation from it, and share only the interface. You do that by putting the interface definition in a public header file. No __declspec(dllexport) statement is needed. Exporting C++ classes is very bad news. __declspec(dllexport) should be used only for ''extern "C"'' functions.
> class MyClass { public: MyClass(); MyClass(const MyClass& ); 私人: MyClass& operator =(const MyClass&); typedef std :: map< SomeKey,SomethingElseTreasureChest; TreasureChest m_treasures; }; > class MyClass { public: MyClass(); MyClass(const MyClass&); private: MyClass& operator=(const MyClass&); typedef std::map<SomeKey, SomethingElseTreasureChest ; TreasureChest m_treasures; };
更多推荐
在DLL中导出C ++对象
发布评论