I wrote code for lib and experimented with the default Win32 console application to make everything work. Since I finished all the classes, I wanted to extract everything in the DLL, and so I started the adaptation with a regular macro:
#ifdef MYLIB_EXPORTS #define DllExport __declspec(dllexport) #else #define DllExport __declspec(dllimport) #endif
I use one interface in my code, which is defined as follows:
__interface DllExport ISerializable { void Serialize(); };
And it worked when I used this code in my exe. In dll I get an error at compile time that says
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 &'
for each class that inherits ISerializable to implement the necessary methods. (I use std::shared_ptr<ISerializable> several times to have an abstraction in my code.) However, when I change __interface to class and make all methods pure virtual, I do not get this error, and compilation succeeds.
Why am I getting this error? Why do I need an assignment operator for my class / interface in my DLL? Is there a workaround?
(Using RTM for Visual Studio 2012 in RTM for Windows 8 with C ++ 11.)
Here is one segment where this error occurs (the error always refers to the last } class):
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); };
This error also occurs in the class where I have a property similar to the Tile class, where I use std::shared_ptr<ISerializable> .