给下面每一行代码给上注释#include "pch.h" #include "FinBudgetFlowManager.h" int FinBudgetFlowManager::C(double _value, time_t _time, CString _remark, FlowType _type) { FinBudgetFlow* pFBD = new FinBudgetFlow(); pFBD->setValue(_value); pFBD->setTime(_time); pFBD->setRemark(_remark); pFBD->setType(_type);; this->FlowMap.insert(std::map<int, FinBudgetFlow*>::value_type(this->getSize(), pFBD)); return this->getSize()-1; } bool FinBudgetFlowManager::U(int _index, double _value, time_t _time, CString _remark, FlowType _type){ std::map<int, FinBudgetFlow*>::iterator iter; iter = this->FlowMap.find(_index); if (iter != this->FlowMap.end()) { delete iter->second; iter->second = NULL; this->FlowMap.erase(iter); FinBudgetFlow *pFBD = new FinBudgetFlow(); pFBD->setValue(_value); pFBD->setTime(_time); pFBD->setRemark(_remark); pFBD->setType(_type); this->FlowMap.insert(std::map<int, FinBudgetFlow*>::value_type(_index, pFBD)); return true; } else { throw _index; } } FinBudgetFlow* FinBudgetFlowManager::R(int _index) { std::map<int, FinBudgetFlow*>::iterator iter; iter = this->FlowMap.find(_index); if (iter != this->FlowMap.end()) { return iter->second; } else { throw _index; } } bool FinBudgetFlowManager::D(int _index) { std::map<int, FinBudgetFlow*>::iterator iter; iter = this->FlowMap.find(_index); if (iter != this->FlowMap.end()) { delete iter->second; iter->second = NULL; //防止野指针这一步是否真的需要? this->FlowMap.erase(iter); return true; } else { throw _index; } } int FinBudgetFlowManager::getSize() { return FlowMap.size(); }
时间: 2024-04-05 19:31:17 浏览: 25
//引入预编译头文件
#include "pch.h"
//引入头文件"FinBudgetFlowManager.h"
#include "FinBudgetFlowManager.h"
//定义函数C,返回类型为int,参数为value,time,remark和type
int FinBudgetFlowManager::C(double _value, time_t _time, CString _remark, FlowType _type) {
//创建一个新的FinBudgetFlow对象
FinBudgetFlow* pFBD = new FinBudgetFlow();
//设置新对象的value
pFBD->setValue(_value);
//设置新对象的time
pFBD->setTime(_time);
//设置新对象的remark
pFBD->setRemark(_remark);
//设置新对象的type
pFBD->setType(_type);;
//将新对象插入到FlowMap中
this->FlowMap.insert(std::map<int, FinBudgetFlow*>::value_type(this->getSize(), pFBD));
//返回FlowMap的大小减一
return this->getSize()-1;
}
//定义函数U,返回类型为bool,参数为index,value,time,remark和type
bool FinBudgetFlowManager::U(int _index, double _value, time_t _time, CString _remark, FlowType _type){
//定义一个迭代器
std::map<int, FinBudgetFlow*>::iterator iter;
//在FlowMap中查找index
iter = this->FlowMap.find(_index);
//如果找到了
if (iter != this->FlowMap.end()) {
//删除原有对象
delete iter->second;
iter->second = NULL;
//从FlowMap中删除原有对象
this->FlowMap.erase(iter);
//创建一个新的FinBudgetFlow对象
FinBudgetFlow *pFBD = new FinBudgetFlow();
//设置新对象的value
pFBD->setValue(_value);
//设置新对象的time
pFBD->setTime(_time);
//设置新对象的remark
pFBD->setRemark(_remark);
//设置新对象的type
pFBD->setType(_type);
//将新对象插入到FlowMap中
this->FlowMap.insert(std::map<int, FinBudgetFlow*>::value_type(_index, pFBD));
//返回true
return true;
}
//如果没有找到
else {
//抛出异常
throw _index;
}
}
//定义函数R,返回类型为FinBudgetFlow*,参数为index
FinBudgetFlow* FinBudgetFlowManager::R(int _index) {
//定义一个迭代器
std::map<int, FinBudgetFlow*>::iterator iter;
//在FlowMap中查找index
iter = this->FlowMap.find(_index);
//如果找到了
if (iter != this->FlowMap.end()) {
//返回找到的对象
return iter->second;
}
//如果没有找到
else {
//抛出异常
throw _index;
}
}
//定义函数D,返回类型为bool,参数为index
bool FinBudgetFlowManager::D(int _index) {
//定义一个迭代器
std::map<int, FinBudgetFlow*>::iterator iter;
//在FlowMap中查找index
iter = this->FlowMap.find(_index);
//如果找到了
if (iter != this->FlowMap.end()) {
//删除对象
delete iter->second;
iter->second = NULL;
//从FlowMap中删除对象
this->FlowMap.erase(iter);
//返回true
return true;
}
//如果没有找到
else {
//抛出异常
throw _index;
}
}
//定义函数getSize,返回类型为int
int FinBudgetFlowManager::getSize() {
//返回FlowMap的大小
return FlowMap.size();
}
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)