I exported an dll of a class inherited from std::string.
I used it in another project, but there is a compilation error
"
Error 5 error LNK2005: "public: __cdecl std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ) already defined in tps_frame.obj J:\ciplan_workstation\build\app\tpsUtilsd.lib(tpsUtilsd.dll)
"
I am not sure the problem was caused by the dll or lib. Until now, I have not found out the reason.
The code as following:
//line_string.h
#include <string>
#include <iostream>
class __declspec(dllexport) line_string : public std::string
{
friend std::istream& operator>>(std::istream& is, line_string& str);
public:
inline operator std::string&() { return *this; }
};
//line_string.cpp
#include "line_string.h"
std::istream& operator>>(std::istream& is, line_string& str)
{
std::getline(is, static_cast<std::string&>(str));
return is;
}
#if defined(_DLL)
class __declspec(dllexport) line_string : public std::string
#else
class __declspec(dllimport) line_string : public std::string
#endif