【发布时间】:2015-07-31 21:09:38
【问题描述】:
我正在尝试从具有 stl 成员的 DLL 中导出 C++ 类。
这是我的主要课程。
class MATHFUNCSDLL_API MyMathFuncsImpl
{
public:
std::vector<int> vi;
std::string getString();
void setString(std::string s);
private:
std::string s;
};
使用这些方法有效,但在 VS 2012 上会发出关于 std::string 和 std::vector 没有 dll 接口的警告。现在当我这样做时 -
class MATHFUNCSDLL_API MyMathFuncs
{
public:
MyMathFuncs()
{
pImpl = new MyMathFuncsImpl();
}
std::string getString()
{
return pImpl->getString();
}
std::vector<int> getVector()
{
return pImpl->vi;
}
void setString(std::string news)
{
pImpl->setString(news);
}
private:
MyMathFuncsImpl* pImpl;
};
我没有收到任何警告,它也有效。我的问题是:有这样的接口真的能解决问题吗(stl 成员可能在 dll 边界上以不同的方式实现),还是只是抑制编译器问题的一个技巧?
【问题讨论】:
-
我认为这可行(根据 Zan Lynx 的回答),但对于使用不同标准 C++ 库实现的客户来说可能仍然存在问题