0x00 唠唠叨叨
工作那么长时间stl容器很少去存储简单类型,一般都是利用stl容器的特性,去存储复杂类型,比如:类对象、结构体....
0x01 实例操作
class CheckInfo
{
public:
CheckInfo(std::string _strTime, std::string _token)
{
if (!_strTime.empty())
{
this->m_time = _strTime;
}
if (!_token.empty())
{
this->m_token = _token;
}
}
//m_time get/set函数
bool SetTime(const std::string& _time)
{
if (_time.empty())
{
return false;
}
this->m_time = _time;
return true;
}
std::string GetTime()
{
return this->m_time;
}
//m_token get/set函数
bool SetToken(const std::string& _token)
{
if (_token.empty())
{
return false;
}
this->m_token = _token;
return true;
}
std::string GetToken()
{
return this->m_token;
}
private:
std::string m_time;
std::string m_token;
};
int main(int argc, char* argv[])
{
vector<CheckInfo*> info;
CheckInfo phoneInfo("2017年11月14日 07:29:07","reacher123");
CheckInfo personInfo("2017年11月14日 07:29:07", "123reacher");
info.push_back(&phoneInfo);
info.push_back(&personInfo);
/* 根据vector的特性,使用数组的方式得到存储在vector内部的对象地址,
再使用指针指向实例对象的堆空间,
然后调用实例对象的函数
*/
cout << (*info[0]).GetTime() << endl;
return 0;
}
0x02 使用到的姿势点
为了方便不了解的朋友方便学习,罗列了一下使用到的知识点
vector 的特性,数组,指针,类,堆空间申请
0x03 遇到的bug
昨天上班到太晚了,起床有点头晕,在#include "stdafx.h"定义了抽象类,晕乎乎又写了一边,搞成了重复定义,晕了一会才看错误提醒,出现问题记得一定要先看错误提示,根据错误提示再看代码上下文,就可能大致推断出bug出现的原因和定位到bug的位置。