64,643
社区成员
发帖
与我相关
我的任务
分享
// There's class contains data whose source code could not be modified
// and we define class appdataset using them
#define DATA1_LEN 100
class data1 {
int *m_data;
public:
data1(): m_data(new int[DATA1_LEN]) {}
~data1() { delete[] m_data; }
};
#define DATA2_LEN 200
class data2 {
int *m_data;
public:
data2(): m_data(new int[DATA2_LEN]) {}
~data2() { delete[] m_data;}
};
// appdataset using the class upwards
// check out the code, and fix the bugs in the following code.
class appdataset {
typedef map(string, void*) dataset;
dataset m_dataset;
public:
template <class data>
string add(data *pdata) {
string strID = generateID(pdata);
m_dataset.insert(pair<string, void*>(strID, pdata));
return strID;
}
template <class data>
string generateID(data* pdata) {
/* omit */
}
void remove(string strID) {
dataset::iterator it = m_dataset.find(strID);
if(m_dataset.end() != it) {
delete it->second;
}
m_dataset.erase(it);
}
};