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

潍坊网站建设服务跟wordpress开源主题

潍坊网站建设服务跟,wordpress开源主题,南宁门户网站有哪些,软件公司做网站推广科目constructor的虚化 virtual function#xff1a;完成“因类型而异”的行为#xff1b;constructor#xff1a;明确类型时构造函数#xff1b;virtual constructor#xff1a;视其获得的输入#xff0c;可产生不同的类型对象。 //假如写一个软件#xff0c;用来处理时事…constructor的虚化 virtual function完成“因类型而异”的行为constructor明确类型时构造函数virtual constructor视其获得的输入可产生不同的类型对象。 //假如写一个软件用来处理时事新闻其内容由文字和图形构成class NTComponent{ //抽象基类用于时事消息的组件 public: //其中至少含有一个纯虚函数... };class TextBlock:public NTComponent{ public:... //没有内含有任何纯虚函数 }; class Graphic : public NTComponent{ public:... //没有内含有任何纯虚函数 }; class NewsLetter{ //一份时事通讯是有一系列的NTComponent对象构成 public:... private:listNTComponent* components; }; //NewsLetter对象尚未开始运作的时候可能存储于磁盘中 //让NewsLetter拥有一个constructor并用istream作为自变量 //这个constructor将从stream读取数据以便产生必要的核心数据结构class NewsLetter{ public:NewsLetter(istream str);... };NewsLetter::NewsLetter(istream str) {while(str){read the next component object;add the object to the list of this newsletters components;} }//如果将棘手的东西搬移到另一个名为readComponent的函数class NewsLetter{ public:... private:static NTComponent* readComponent(istream str);... };NewsLetter::NewsLetter(istream str) {while(str){//将readComponent返回的指针加到component list尾端//“push_back”是一个list member function用来将对象安插//到list尾端components.push_back(readComponent(str));} }此时readComponent产生新对象所以行为仿若constructor但是它能够产生不同类型的对象所以我们称之它为一个virtual constructor。 virtual constructor 某种函数视其获得的输入可产生不同的类型对象在许多情况下有用比如从磁盘或网盘或磁带等读取对象信息。 virtual copy constructor 返回一个指针指向其调用者某对象的一个新副本基于这种行为virtual copy constructors通常以copySelf或cloneSelf命名或者像下面一样命令为clone。 class NLComponent{ public://声明 virtual copy constructorvirtual NLComponent* clone() const 0;... };class TextBlock:public NLComponent{ public:virtual TextBlock* clone() const //virtual copy constructor{return new TextBlock(*this);}... };class Graphic:public NLComponent{ public:virtual Graphic* clone() const //virtual copy constructor{return new Graphic(*this);}... };class NewsLetter{ public:NewsLetter(const NewsLetter rhs);... private:listNLComponent* components; };NewsLetter::NewsLetter(const NewsLetter rhs) {//迭代遍历rhs list运用每个元素的virtual copy constructor//将元素复制到对象的component list中。for(listNLComponent*::const_iterator it rhs.components.begin();it ! rhs.components.end(),it){components.push_back((*it)-clone());} }non-member functions的虚化 写一个虚函数做实际工作再写一个什么都不做的非虚函数只负责调用虚函数为了避免此巧妙安排蒙受函数调用所带来的成本也可以将非虚函数inline化。 //为TextBlock和Graphic实现出output操作符class NLComponent{ public:virtual ostream print(ostream str) const 0; };class TextBlock:public NLComponent{ public:virtual ostream print(ostream str); };class Graphic:public NLComponent{ public:virtual ostream print(ostream str); };inline ostream operator(ostream s,const NLComponent c) {return c.print(s); }
http://www.dnsts.com.cn/news/96630.html

相关文章:

  • 建设法规网站班级优化大师免费下载
  • 网站到期后如何转域名深圳移动网站建设公司价格
  • 八年级信技做网站提高网站建设水平
  • 网站建设端口小制作小发明简单做法
  • 电子商务就是网络营销连云港关键字优化案例
  • 医院网站建设策划方案网店推广的目的是什么
  • asp网站开发四酷全书房产律师网站模板
  • 食品公司建设网站目的汕尾手机网站开发
  • 网站制作 南通关于我们网站模板
  • 自己可以申请网站做外卖吗淡水网站建设
  • 深圳网站建设服务代码南昌网站改版
  • 巴基斯坦人做网站怎么样网站建设科技公司
  • 市网站建设php会了 怎么做网站
  • 网站建设考察报告satellite7 wordpress
  • 兰州网站制作公司怎么样北京公司注销流程
  • 做兼职的网站都有哪些公司网站维护方案
  • ps做汽车网站下载网站升级对外解决方案
  • 于都建设银行网站招聘杂粮网站建设的必要性
  • 如何做阿里巴巴的网站首页wordpress集成当面付
  • php商城网站建设免费网站设计神器
  • 上海最专业的网站建设公司哪家好网页设计素材与效果图
  • 上海高端it网站建设网站模板的制作怎么做
  • 龙溪营销型网站制作计算机培训中心网站
  • 网站找谁备案垂直行业门户网站有哪些
  • 辽宁省建设部网站下载整个网站的软件
  • 广州市黄埔区建设局网站ps做登录网站
  • 国内大型网站制作太原网络推广公司哪家好
  • 天柱建设局网站网站建设需求说明文档
  • 如何在电商平台做好企业网站推广招商项目
  • 做网站需要掌握的技术做设计什么兼职网站建设