|
如何在Dll中导出STL类 关键字:DLL STL
//导出stl类 std::vector<CPerson>
class CPerson
{
public:
int m_nAge;
char m_strName[40];
public:
bool operator < (const CPerson& c) const
{
return true;
}
bool operator == (const CPerson& c) const
{
return true;
}
};
EXPIMP_TEMPLATE template class VECDLL_API std::vector<CPerson> //显示实例化模板类
VECDLL_API int fnVecDll(std::vector<CPerson>& vecPer); //导出函数 定义这两个运算符的原因是:所有stl容器都有“比较”成员函数,这些成员函数需要调用自定义类型的<和==运算符。通常情况下,由于没有使用这些成员函数,所以它们没有被实例化,所以我们使用时一般就不需要为CPerson定义这两个运算符。然而,当显示实例化此容器类时,它所有的成员函数都需实例化,包括它的“比较”成员函数,所以这时必须实现CPerson的<和==运算符。如果CPerson并不在乎<和==的意义,我们可以像上面代码所示通过简单返回true来实现它们。 导出一个“数据成员包含stl对象”的类。方法与上类似。如下代码所示: EXPIMP_TEMPLATE template class VECDLL_API std::vector<int> //显示实例化std::vector<int>
class VECDLL_API CContainer
{
public:
std::vector<int> m_vecNum;
}; 完整例子请查看实例代码。 |
背景:
阅读新闻
如何在Dll中导出STL类
| [日期:2005-12-29] | 作者: | [字体:大 中 小] |
阅读: 次
【 打印 】
【 打印 】
相关新闻
相关关键词: stl
全站导航
gmail.com