项目中实例代码如下:
///取消订阅行情 void MdSpi::UnSubMarket(list<string> *l_instrument) { list<string>::iterator itor; char **instrumentID = new char *[l_instrument->size()]; int size = l_instrument->size(); int i = 0; const char *charResult; for (itor = l_instrument->begin(), i = 0; itor != l_instrument->end(); itor++, i++) { cout << *itor << endl; charResult = (*itor).c_str(); instrumentID[i] = new char[strlen(charResult) + 1]; strcpy(instrumentID[i], charResult); } USER_PRINT(this->mdapi); this->mdapi->UnSubscribeMarketData(instrumentID, size); // 析构字符串数组 for (i = 0; i < size; i++) { delete[]instrumentID[i]; } delete[]instrumentID; // 取消订阅列表里清空 for (itor = l_instrument->begin(); itor != l_instrument->end();) { (*itor).clear(); itor = l_instrument->erase(itor); } }
从中可以抽取出多维数组的初始化析构如下:
初始化:
int **pArr=new int*[5]; for(int k=0;k<5;k++) pArr[k] = new int[5];
析构:
for(i=0;i<5;i++) delete []pArr[i]; delete []pArr;
文章的脚注信息由WordPress的wp-posturl插件自动生成