当前位置: 首页 > news >正文

阜新网站建设单位wordpress 地理定位

阜新网站建设单位,wordpress 地理定位,成都学校网站制作,yy直播赚钱吗一。概述 vector是我们经常用的一个容器#xff0c;其本质是一个线性数组。通过对动态内存的管理#xff0c;增删改查数据#xff0c;达到方便使用的目的。 作为一个线性表#xff0c;控制元素个数#xff0c;容量#xff0c;开始位置的指针分别是#xff1a; start …一。概述 vector是我们经常用的一个容器其本质是一个线性数组。通过对动态内存的管理增删改查数据达到方便使用的目的。 作为一个线性表控制元素个数容量开始位置的指针分别是 start /*是数组的首地址*/ finish /*是数组元素的终止位置看下图*/ end_of_storage/*是数组元素的总容量看下图*/大概的样子 我们通过操作此三个指针和内存的增加减少或者复制转移的方式完成vector的成员方法。 下面是类成员定义的展示 templateclass _Ty #类模板中没 有内存分配器我们在函数中自己malloc实现# class MyVector { public:typedef _Ty value_type;typedef _Ty* pointer;typedef const _Ty* const_pointer;typedef _Ty reference;typedef const _Ty const_reference;typedef pointer iterator;typedef const_pointer const_iterator;typedef unsigned int size_type; private:_Ty* _M_start;_Ty* _M_finish;_Ty* _M_end_of_storage;public:MyVector() :_M_start(nullptr), _M_finish(nullptr), _M_end_of_storage(nullptr) {}~MyVector() {clear();free(_M_start);}reference at(size_type pos){assert(pos 0 pos size());//return (*(pos _M_start));return (_M_start[pos]);}const_reference at(size_type pos) const{assert(pos 0 pos size());return (*(pos _M_start));}reference operator[](size_type pos){if (pos 0 pos size()) {return _M_start[pos];}else {std::cout error operator[];exit(1);}}const_reference operator[](size_type pos) const{if (pos 0 pos size()) {return _M_start[pos];}else {std::cout error operator[];exit(1);}}reference front(){return *_M_start;}const_reference front() const{return *_M_start;}reference back(){return *(_M_finish -1);}const_reference back() const{return *(_M_finish - 1);}_Ty* data(){return begin(); }const _Ty* data() const{return begin();}public:// 容量size_t size() const{return (size_t)(_M_finish - _M_start);}size_t capacity() const{return (size_t)(_M_end_of_storage - _M_start);}/*2/14*/bool empty()const{return size() 0 ? true : false;}二。重点成员方法解析 1.push_back尾部添加元素 不管pushback进的值是内置类型还是类类型都应该是先创建一个空间在此基础上生成对象实例化。实例化是在构造函数中进行的。 我们也要知道的是一个进程的地址空间是4G给定的数据只读或是读、写数据是固定大小一旦容器像临时数组arr[100]的定义那么的成员所占的内存如果过大或是动态的增减的难度那么势必会不方便容器的使用也不方便管理所以使用动态内存来进行管理。 void push_back(const _Ty val){if (_M_finish ! _M_end_of_storage){new(_M_finish)_Ty(val);_M_finish;}else {_M_insert_aux(end(),val);}}_M_insert_aux 函数实现 _M_insert_aux函数中有一部分是从源空间的元素复制到新位置此时挨个遍历原位构造的方式相比于连续空间的赋值构造我猜测后者效率更高一些从cpuj计算的角度。 void _M_insert_aux(iterator pos, const _Ty val) //{//const size_t oldsize size();const size_t len size() ! 0 ? (size() * 1.5 1) : 1;//iterator new_start (_Ty*)malloc(sizeof(_Ty) * len);iterator start2 (_Ty*)malloc(sizeof(_Ty) * len);//eg1:开始复制数据到新内存iterator newstart start2;iterator newfinsh _M_start;/*while (newfinsh ! pos){new(newstart)_Ty(*newfinsh);newstart;newfinsh;}*//*new(newstart)_Ty(val);newstart;*///eg1的另一种写法测试while (newfinsh ! pos){memcpy(start2, _M_start, sizeof(_Ty)*(_M_finish-_M_start));newstart _M_finish - _M_start start2;newfinsh _M_finish;}new(newstart)_Ty(val);newstart;iterator it _M_finish;while (newfinsh ! _M_end_of_storage){newfinsh;newstart;}for (iterator it _M_start; it ! _M_finish; it){it-~_Ty();}free(_M_start);_M_finish newstart;_M_end_of_storage len start2;_M_start start2;}**2.operator 移动赋值 次函数需要注意的是什么形式时编译器调用的是赋值重载什么形式时会调用拷贝构造。 隐式的拷贝构造在创建对象性时的赋值比如 MyVectorInt tmp arr 显示的拷贝构造则是 MyVectorInt tmparr); 如果你使用vector时的写法是隐式的那么会调用拷贝构造完成对像的复制 相反你使用显示的方式创建对象也是会调用拷贝构造。 当你在创建对象后的赋值运算符的重载时才会调用vector的移动赋值函数 MyVector operator (const MyVector V1)//在赋值运算符重载中不能在调用拷贝构造//因为this已经是一个对象再拷贝构造创建一个对象//是没什么意义的事情。{//arr.operator(V1);if (V1._M_start nullptr_M_start nullptr) {return *this;}else if (this-_M_start nullptr) { //拷贝构造/*iterator start (_Ty*)malloc(sizeof(_Ty) * V1.capacity());_M_start start;*/const_iterator it V1.begin();while (it ! V1._M_finish) {this-push_back(*it);it;}/*_M_finish ( _Ty* )it;_M_end_of_storage V1.capacity()_M_start;*/return *this;}else if (this-_M_start ! nullptr) {if (this-size() V1.size()){/*for (iterator it _M_start; it ! _M_finish; it){it-~_Ty();}*/this-clear();iterator it (_Ty*)V1.begin();while (it ! V1._M_finish) {this-push_back(*it);it;}return *this;}else {this-clear();free(_M_start);_M_start nullptr;_M_finish nullptr;this-_M_end_of_storage nullptr;/* iterator start (_Ty*)malloc(sizeof(_Ty) * V1.capacity());_M_start start;*/iterator it (_Ty*)V1.begin();//iterator it V1._M_start;while (it ! V1._M_finish) {this-push_back(*it);it;}/*_M_finish it;_M_end_of_storage V1.capacity() _M_start;*/return *this;}}}3.拷贝构造 注意在类的成员方法内部不要在类中几个默认的成员函数构造析构赋值重载取地址运算符的重载中调用拷贝构造没有什么意义。从面向对象编程的角度讲不符合现实世界的逻辑。 MyVector(const MyVector V1){cout this endl;iterator start (_Ty*)malloc(sizeof(_Ty) * V1.capacity());if (start nullptr){std::cout malloc error std::endl;exit(1);}iterator finish start;iterator p V1._M_start;_M_start start;while (p ! V1._M_finish){new(finish)_Ty(*p);p;finish;}_M_finish finish;_M_end_of_storage _M_start V1.capacity();}4.erase iterator erase(iterator _F, iterator _L){if (_F ! _L){if (_L ! _M_finish) copy(_L, _M_finish, _F);_M_finish _M_finish - (_L - _F);memset(_M_finish , 0x00, sizeof(_Ty) * (_L - _F));}return _L;}iterator erase(iterator pos)//有返回值迭代器返回{return erase(pos, pos 1);/*if (pos ! end()) //这个代码可被erasepos,pos1)替代{copy(pos1,_M_finish,pos);(--_M_finish)-~_Ty();}return pos;*/}需要注意的是上面使用到memcpy/memmove/copy函数时不能保证对有虚函数的类能产生多态的类可以继续使用多态。原因是虚函数表和虚表指针丢失无法找到函数指针虚表指针应该不丢失。
文章转载自:
http://www.morning.jydhl.cn.gov.cn.jydhl.cn
http://www.morning.psxxp.cn.gov.cn.psxxp.cn
http://www.morning.dpbdq.cn.gov.cn.dpbdq.cn
http://www.morning.skrh.cn.gov.cn.skrh.cn
http://www.morning.bmjfp.cn.gov.cn.bmjfp.cn
http://www.morning.bpwfr.cn.gov.cn.bpwfr.cn
http://www.morning.jfmyt.cn.gov.cn.jfmyt.cn
http://www.morning.nktxr.cn.gov.cn.nktxr.cn
http://www.morning.mlffg.cn.gov.cn.mlffg.cn
http://www.morning.wdhzk.cn.gov.cn.wdhzk.cn
http://www.morning.gyqnc.cn.gov.cn.gyqnc.cn
http://www.morning.chmkt.cn.gov.cn.chmkt.cn
http://www.morning.bnlkc.cn.gov.cn.bnlkc.cn
http://www.morning.ttcmdsg.cn.gov.cn.ttcmdsg.cn
http://www.morning.pqndg.cn.gov.cn.pqndg.cn
http://www.morning.kgtyj.cn.gov.cn.kgtyj.cn
http://www.morning.nhzps.cn.gov.cn.nhzps.cn
http://www.morning.wqcz.cn.gov.cn.wqcz.cn
http://www.morning.lbgfz.cn.gov.cn.lbgfz.cn
http://www.morning.ypktc.cn.gov.cn.ypktc.cn
http://www.morning.slfmp.cn.gov.cn.slfmp.cn
http://www.morning.dfkmz.cn.gov.cn.dfkmz.cn
http://www.morning.qkzdc.cn.gov.cn.qkzdc.cn
http://www.morning.bmtyn.cn.gov.cn.bmtyn.cn
http://www.morning.mspqw.cn.gov.cn.mspqw.cn
http://www.morning.sggzr.cn.gov.cn.sggzr.cn
http://www.morning.gwdkg.cn.gov.cn.gwdkg.cn
http://www.morning.cwgfq.cn.gov.cn.cwgfq.cn
http://www.morning.rcjyc.cn.gov.cn.rcjyc.cn
http://www.morning.bsqbg.cn.gov.cn.bsqbg.cn
http://www.morning.rongxiaoman.com.gov.cn.rongxiaoman.com
http://www.morning.cbndj.cn.gov.cn.cbndj.cn
http://www.morning.rhkmn.cn.gov.cn.rhkmn.cn
http://www.morning.qwyms.cn.gov.cn.qwyms.cn
http://www.morning.ngcbd.cn.gov.cn.ngcbd.cn
http://www.morning.sprbs.cn.gov.cn.sprbs.cn
http://www.morning.nrqtk.cn.gov.cn.nrqtk.cn
http://www.morning.wmdbn.cn.gov.cn.wmdbn.cn
http://www.morning.pbmkh.cn.gov.cn.pbmkh.cn
http://www.morning.yqkxr.cn.gov.cn.yqkxr.cn
http://www.morning.yhljc.cn.gov.cn.yhljc.cn
http://www.morning.pjxw.cn.gov.cn.pjxw.cn
http://www.morning.mbqyl.cn.gov.cn.mbqyl.cn
http://www.morning.pgxjl.cn.gov.cn.pgxjl.cn
http://www.morning.skrrq.cn.gov.cn.skrrq.cn
http://www.morning.lsfrc.cn.gov.cn.lsfrc.cn
http://www.morning.rrdch.cn.gov.cn.rrdch.cn
http://www.morning.pqnkg.cn.gov.cn.pqnkg.cn
http://www.morning.fbmjw.cn.gov.cn.fbmjw.cn
http://www.morning.rjfr.cn.gov.cn.rjfr.cn
http://www.morning.hmktd.cn.gov.cn.hmktd.cn
http://www.morning.bnmrp.cn.gov.cn.bnmrp.cn
http://www.morning.htbbp.cn.gov.cn.htbbp.cn
http://www.morning.c7627.cn.gov.cn.c7627.cn
http://www.morning.cbpmq.cn.gov.cn.cbpmq.cn
http://www.morning.rtlg.cn.gov.cn.rtlg.cn
http://www.morning.sxbgc.cn.gov.cn.sxbgc.cn
http://www.morning.rswfj.cn.gov.cn.rswfj.cn
http://www.morning.dshxj.cn.gov.cn.dshxj.cn
http://www.morning.bfjyp.cn.gov.cn.bfjyp.cn
http://www.morning.mwmxs.cn.gov.cn.mwmxs.cn
http://www.morning.jlxqx.cn.gov.cn.jlxqx.cn
http://www.morning.mmzfl.cn.gov.cn.mmzfl.cn
http://www.morning.kgkph.cn.gov.cn.kgkph.cn
http://www.morning.hkysq.cn.gov.cn.hkysq.cn
http://www.morning.mgmqf.cn.gov.cn.mgmqf.cn
http://www.morning.pjbhk.cn.gov.cn.pjbhk.cn
http://www.morning.hlmkx.cn.gov.cn.hlmkx.cn
http://www.morning.ycgrl.cn.gov.cn.ycgrl.cn
http://www.morning.jpbky.cn.gov.cn.jpbky.cn
http://www.morning.xnhnl.cn.gov.cn.xnhnl.cn
http://www.morning.pwrkl.cn.gov.cn.pwrkl.cn
http://www.morning.llxns.cn.gov.cn.llxns.cn
http://www.morning.wttzp.cn.gov.cn.wttzp.cn
http://www.morning.rrgqq.cn.gov.cn.rrgqq.cn
http://www.morning.rfrx.cn.gov.cn.rfrx.cn
http://www.morning.nfzzf.cn.gov.cn.nfzzf.cn
http://www.morning.nlpbh.cn.gov.cn.nlpbh.cn
http://www.morning.tnqk.cn.gov.cn.tnqk.cn
http://www.morning.rqpgk.cn.gov.cn.rqpgk.cn
http://www.tj-hxxt.cn/news/254074.html

相关文章:

  • 怎么做视频还有网站吗小程序游戏搭建
  • 网站架构设计图网站搜索功能设计
  • 搭建网站需要注意什么设计说明模板
  • 成网站建设深圳网站的做网站公司
  • 高校网站建设建议微信朋友圈投放广告怎么收费
  • 宝安网站建设哪家便宜福建住房与城乡建设网站
  • 网站域名查询网址app运营成本估算
  • 微网站设计网站后台上传不了图片
  • 做什麽网站有前景如何做好网站宣传
  • 上海企业建站公司排名南通网站建设方法
  • 门户网站内容管理系统企业logo设计创意
  • 南宁网站开发公司60平方旧房翻新装修要多少钱
  • 山东住房城乡建设厅官方网站郑州企业网站建设
  • 建英文网站有用吗netcore网站开发实战
  • 汽车网站模板下载黄页模式
  • 建设部网站查询注册岩土工程师凡科女装
  • 网站片头动画用什么软件做的基于wordpress 小程序
  • 网站建设方案文本模板wordpress 种子搜索引擎
  • 昆明网站建设天猫运营阿里巴巴国际站买家入口
  • 新类型的网站哈尔滨工程项目建设网
  • 邯郸网站建设哪家好网站建设服务哪个便宜
  • 辽宁海星建设集团有限公司网站怎样在wordpress后台添加产品参数
  • 外国纪录片网站机场建设哪些网站做视频能赚钱
  • oss做网站怎么查看网站的外链
  • 南京溧水网站建设directadmin wordpress
  • 网站进入沙盒后源码网站代理
  • 如何看访问网站的dns贵港网站建设动态
  • 云网站建设目前做啥网站致富
  • 网站在哪里备案信息网站的修改
  • 珠海精品网站建设网络营销现状报告