Operator =不是DLL中导出的C __interface的成员
我一直在为lib编写一些代码,并尝试使用默认的Win32控制台应用程序来运行所有内容.由于我已经完成了所有类,我想将所有内容提取到DLL中,因此我开始使用通常的宏进行调整:
#ifdef MYLIB_EXPORTS #define DllExport __declspec(dllexport) #else #define DllExport __declspec(dllimport) #endif 我在我的代码中使用一个接口,其定义如下: __interface DllExport ISerializable { void Serialize(/* ... */); /* some other methods */ }; 这在我的exe中使用这段代码时起作用了.在DLL中,我在编译过程中遇到错误 error C2039: '=' : is not a member of 'MyLib::ISerializable' error C2664: 'MyLib::DerivedClass::operator =' : cannot convert parameter 1 from 'const MyLib::ISerializable' to 'const MyLib::DerivedClass &' 对于每个继承ISerializable的类来实现所需的方法. (我使用std :: shared_ptr< ISerializable>几次在我的代码中进行抽象.)但是,当我将__interface更改为类并使所有方法都是纯虚拟时,我不会收到此错误并且编译成功. 为什么我会收到此错误?为什么我的DLL中的类/接口需要赋值运算符?有没有解决方法? (在带有C 11的Windows 8 RTM上使用Visual Studio 2012 RTM.) 以下是发生此错误的一个段(错误始终指向类的最后一个}): class DllExport Tile final : public ISerializable { public: __declspec(property(get=GetIsPassable,put=SetIsPassable)) bool IsPassable; __declspec(property(get=GetTileId,put=SetTileId)) uint16_t TileId; bool& GetIsPassable() { return this->_IsPassable; } void SetIsPassable(bool val) { this->_IsPassable = val; } uint16_t& GetTileId() { return this->_TileId; } void SetTileId(uint16_t val) { this->_TileId = val; } bool _IsPassable; uint16_t _TileId; void Serialize(OutputFileStream& ofs); size_t TellSize(); size_t Unserialize(InputFileStream& ifs,size_t metadata = 0); }; 这个错误也发生在我有类似Tile类的属性的类中,我使用std :: shared_ptr< ISerializable>. 解决方法
我猜接口没有编译器生成的复制构造函数或赋值运算符.
一种可能的解决方案是显式实现DerivedClass :: operator =.那是因为编译器生成的版本将尝试调用不存在的ISerializable :: operator =.复制构造函数也是如此. 另一个解决方案是让所有类COM类:) 例 使用你的Tile类: class DllExport Tile final : public ISerializable { public: Tile(const Tile& tile) : _IsPassable(tile._IsPassable),_TileId(tile._TileId) { } /* New Code START */ Tile& operator=(const Tile& tile) { _IsPassable = tile._IsPassable; _TileId = tile._TileId; return *this; } /* New Code END */ __declspec(property(get=GetIsPassable,put=SetIsPassable)) bool IsPassable; __declspec(property(get=GetTileId,put=SetTileId)) uint16_t TileId; bool& GetIsPassable() { return this->_IsPassable; } void SetIsPassable(bool val) { this->_IsPassable = val; } uint16_t& GetTileId() { return this->_TileId; } void SetTileId(uint16_t val) { this->_TileId = val; } bool _IsPassable; uint16_t _TileId; void Serialize(OutputFileStream& ofs); size_t TellSize(); size_t Unserialize(InputFileStream& ifs,size_t metadata = 0); }; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- windows-server-2008 – 安装Windows Server 200
- windows – 如何告诉FORFILES在路径上执行命令?
- 窗口 – ASLR是否意味着重新设计dll不是必需的?
- Windows 8上的Java 7 Debug无法正常工作
- Windows安装MongoDB
- windows-phone-8 – Windows Embedded 8掌上电脑
- windows平台 pypi打包分发 2019
- script.bat可以对Windows PATH环境变量进行更改
- Azure包不包括链接的项目dll,甚至与副本本地集
- 从Windows 2008 Server同时运行IIS 7和JBoss AS