vector模板类可以存放任何同一类型的对象,其中的元素是连续存储的。要包含头文件#include <vector>
使用方法:例如有一个类CActionInfo
1. 定义vector对象:std::vector<CActionInfo*> katongList;
2. vector插入对象:
int CManage::addKatong(CActionInfo* p_cal)
{
int temp = katongList.size();
katongList.insert(katongList.end(),p_cal);
return temp;
}
3. vector得到对象:
CActionInfo* CManage::getAction( int nID )
{
CActionInfo* temp = GetInstance()->katongList[nID];
return temp;
}
4. vector删除对象:
CActionInfo* temp = CManage::GetInstance()->katongList[ID];
std::vector<CActionInfo*>::iterator it = CManage::GetInstance()->katongList.begin();
CManage::GetInstance()->katongList.erase(it+ID);
delete temp;