C++ Dll导出友元运算符>&燃气轮机;
我正在创建这个类:C++ Dll导出友元运算符>&燃气轮机;,c++,visual-c++,visual-studio-2015,C++,Visual C++,Visual Studio 2015,我正在创建这个类: ///> MyObject.h file class __declspec(dllexport) CMyObject { public: int m_Intero; public: CMyObject(); ~CMyObject(); public: friend std::wifstream& operator>>(std::wifstream& is, CMyObject& eprt); } ///
///> MyObject.h file
class __declspec(dllexport) CMyObject
{
public:
int m_Intero;
public:
CMyObject();
~CMyObject();
public:
friend std::wifstream& operator>>(std::wifstream& is, CMyObject& eprt);
}
///> MyObject.cpp
std::wifstream& operator>>(std::wifstream& is, CMyObject& myobj)
{
if (is.is_open())
///> Input operations.
return is;
}
编译库时没有错误,但在最终项目中使用库时会出现以下错误:
LNK2019 unresolved external symbol reference "class std::basic_ifstream<wchar_t,struct std::char_traits<wchar_t> > & __cdecl operator>>(...) in function "public: void __thiscall ...
LNK2019未解析外部符号引用“函数中的class std::basic_ifstream&u cdecl运算符>>(…)”public:void_uthiscall。。。
我想我必须以某种方式指定必须导出运算符>>函数
如何修改代码?几个方面:
- 您正在导出类,而不是全局(友元)函数。您只是让编译器知道全局函数(运算符重载)是一个好朋友。您需要导出该函数
- 当C++对象相关时,最好不要导出这些函数,因为编译器差异会使类具有不同的大小。