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

电商平台运营费用预算肇庆seo按天计费

电商平台运营费用预算,肇庆seo按天计费,网站怎么做微信支付宝,怎样更换动易2006网站模板多态分为两类 静态多态: 函数重载和 运算符重载属于静态多态,复用函数名动态多态: 派生类和虚图数实现运行时多态 静态多态和动态多态区别: 静态多态的函数地址早绑定 编译阶段确定函数地址动态多态的函数地址晚绑定 运行阶段确定函数地址 1、基本语法 #include &…

多态分为两类

  • 静态多态: 函数重载和 运算符重载属于静态多态,复用函数名
  • 动态多态: 派生类和虚图数实现运行时多态

静态多态和动态多态区别:

  • 静态多态的函数地址早绑定 · 编译阶段确定函数地址
  • 动态多态的函数地址晚绑定 · 运行阶段确定函数地址

1、基本语法

#include <iostream>
using namespace std;
#include <string>//动物类
class Animal {
public://虚函数virtual void speak() {cout << "动物在说话" << endl;}
};//猫类 
class Cat :public Animal {
public://重写 函数返回值类型 函数名 参数列表 完全相同void speak() {cout << "小猫在说话" << endl;}
};//狗类
class Dog :public Animal {
public:void speak() {cout << "小狗在说话" << endl;}
};//执行说话的函数
//地址早绑定 在编译阶段确定函数地址
//如果想执行让猫说话,那么这个函数地址就不能提前绑定,需要在运行阶段进行绑定,地址晚绑定//动态多态满足条件
//1、有继承关系
//2、子类重写父类的虚函数//动态多态的使用
//父类的指针或者引用 指向子类对象void doSpeak(Animal& animal) {  //Animal& animal = cat;animal.speak();
}void test01() {Cat cat;doSpeak(cat);Dog dog;doSpeak(dog);
}int main() {test01();system("pause");return 0;
}

2、案例1:计算器类

案例描述:
分别利用普通写法和多态技术,设计实现两个操作数进行运算的计算器类

#include <iostream>
using namespace std;
#include <string>//普通写法
class Calculator {
public:int getResult(string oper) {if (oper == "+") {return m_Num1 + m_Num2;}else if (oper == "-") {return m_Num1 - m_Num2;}else if (oper == "*") {return m_Num1 * m_Num2;}//如果想扩展新的功能,需要修改源码//在真正的开发中 提倡 开闭原则//开闭原则:对扩展进行开发,对修改进行关闭}int m_Num1;//操作数1int m_Num2;//操作数2
};void test01() {//创建计算器对象Calculator c;c.m_Num1 = 10;c.m_Num2 = 10; cout << c.m_Num1 << "+" << c.m_Num2 << "=" << c.getResult("+") << endl;cout << c.m_Num1 << "-" << c.m_Num2 << "=" << c.getResult("-") << endl;cout << c.m_Num1 << "*" << c.m_Num2 << "=" << c.getResult("*") << endl;
}//利用多态实现计算器
//多态好处:
// 1、组织结构清晰
// 2、可读性强
// 3、对前期和后期拓展和维护性高
//实现计算器抽象类
class AbstractCalculator {
public:virtual int getResult() {return 0;}int m_Num1;int m_Num2;
};//加法计算器类
class AddCalculator :public AbstractCalculator {
public:int getResult() {return m_Num1 + m_Num2;}
};//减法计算器类
class SubCalculator :public AbstractCalculator {
public:int getResult() {return m_Num1 - m_Num2;}
};//乘法计算器类
class MulCalculator :public AbstractCalculator {
public:int getResult() {return m_Num1 * m_Num2;}
};void test02() {//多态使用//父类指针或者引用指向子类对象// //加法运算AbstractCalculator* abc = new AddCalculator;abc->m_Num1 = 100;abc->m_Num2 = 100;cout << abc->m_Num1 << "+" << abc->m_Num2 << "=" << abc->getResult() << endl;//用完后记得销毁delete abc;abc = NULL;		//减法运算abc = new SubCalculator;abc->m_Num1 = 100;abc->m_Num2 = 100;cout << abc->m_Num1 << "-" << abc->m_Num2 << "=" << abc->getResult() << endl;delete abc;abc = NULL;//乘法运算abc = new MulCalculator;abc->m_Num1 = 100;abc->m_Num2 = 100;cout << abc->m_Num1 << "*" << abc->m_Num2 << "=" << abc->getResult() << endl;delete abc;abc = NULL;}int main() {//test01();test02();system("pause");return 0;
}


3、纯虚函数和抽象类

#include <iostream>
using namespace std;
#include <string>class Base {
public://纯虚函数//只要有一个纯虚函数,这个类称为抽象类//抽象类特点://1、无法实例化对象//2、抽象类的子类 必须要重写父类中的纯虚函数,否则也属于抽象类virtual void func() = 0;
};class Son :public Base {
public:virtual void func() {cout << "fun()函数调用" << endl;}
};void test01() {//Base b;//抽象类无法实例化对象//new Base;//抽象类无法实例化对象//Son s;//子类必须重写父类中的纯虚函数,否则无法实例化对象Base* base = new Son;base->func();}int main() {system("pause");return 0;
}

4、案例2:制作饮品

案例描述:
制作饮品的大致流程为: 煮水 冲泡 倒入杯中 加入辅料
利用多态技术实现本案例,提供抽象制作饮品基类,提供子类制作咖啡和茶叶

#include <iostream>
using namespace std;
#include <string>class AbstractDrinking {
public://煮水virtual void Boil() = 0;//冲泡virtual void Brew() = 0;//倒入杯中virtual void PourInCup() = 0;//加入辅料virtual void PutSomething() = 0;//制作饮品void makeDrink() {Boil();Brew();PourInCup();PutSomething();}};//制作咖啡
class Coffee:public AbstractDrinking {
public://煮水virtual void Boil() {cout << "煮农夫山泉" << endl;};//冲泡virtual void Brew() {cout << "冲泡咖啡" << endl;};//倒入杯中virtual void PourInCup() {cout << "倒入杯中" << endl;};//加入辅料virtual void PutSomething() {cout << "加入糖和牛奶" << endl;};
};//制作茶叶
class Tea :public AbstractDrinking {
public://煮水virtual void Boil() {cout << "煮矿泉水" << endl;};//冲泡virtual void Brew() {cout << "冲泡茶叶" << endl;};//倒入杯中virtual void PourInCup() {cout << "倒入杯中" << endl;};//加入辅料virtual void PutSomething() {cout << "加入枸杞" << endl;};
};//制作函数
void doWork(AbstractDrinking* abs) {//AbstractDrinking* abs=new Coffee;abs->makeDrink();delete abs;//释放		
}void test01() {//制作咖啡doWork(new Coffee);cout << "---------------" << endl;//制作茶叶doWork(new Tea);}int main() {test01();system("pause");return 0;
}


5、虚析构和纯虚析构 

虚析构和纯虚析构共性

  • 可以解决父类指针释放子类对象
  • 都需要有具体的函数实现

虚析构和纯虚析构区别:

  • 如果是纯虚析构,该类属于抽象类,无法实例化对象
#include <iostream>
using namespace std;
#include <string>class Animal {
public:Animal() {cout << "Animal构造函数调用" << endl;}//利用虚析构可以解决 父类指针释放子类对象时不干净的问题/*virtual ~Animal(){cout<< "Animal虚析构函数调用" << endl;}*///纯虚析构 需要声明也需要实现virtual ~Animal() = 0;//纯虚函数virtual void speak() = 0;
};
Animal:: ~Animal() {cout << "Animal纯虚析构函数调用" << endl;
}class Cat :public Animal {
public:Cat(string name) {cout << "Cat构造函数调用" << endl;m_Name= new string(name);}virtual void speak() {cout << +m_Name<<"小猫在说话" << endl;}~Cat() {if (m_Name != NULL) {cout << "Cat析构函数调用" << endl;delete m_Name;m_Name = NULL; }}string* m_Name;
};void test01() {Animal* animal = new Cat("Tom");animal->speak();//父类指针在析构时候 不会调用子类中析构函数,导致子类如果有堆区属性,出现内存泄露delete animal;  
}int main() {test01();system("pause");return 0;
}

6、案例三:电脑组装

  • 电脑主要组成部件为 CPU (用于计算),显卡 (用于显示),内存条 (用于存储)
  • 将每个零件封装出抽象基类,并且提供不同的厂商生产不同的零件,例如Intel厂商和Lenovo厂商
  • 创建电脑类提供让电脑工作的函数,并且调用每个零件工作的接口
  • 测试时组装三台不同的电脑进行工作
#include <iostream>
using namespace std;
#include <string>//抽象不同零件类//抽象CPU类
class CPU {
public://抽象的计算函数virtual void calculate() = 0;};//抽象显卡类
class VideoCard {
public://抽象的显示函数virtual void display() = 0;};//抽象内存条类
class Memory {
public://抽象的存储函数virtual void storage() = 0;};//电脑类
class Computer {
public:Computer(CPU* cpu, VideoCard* vc, Memory* mem) {m_cpu = cpu;m_vc = vc;m_mem = mem;}//提供工作的函数void work() {//让零件工作起来,调用接口m_cpu->calculate();m_vc->display();m_mem->storage();}//提供析构函数 释放3个电脑零件~Computer() {//释放cpu零件if (m_cpu != NULL) {delete m_cpu;m_cpu = NULL;}//释放显卡零件if (m_vc != NULL) {delete m_vc;m_vc = NULL;}//释放内存条零件if (m_mem != NULL) {delete m_mem;m_mem = NULL;}}private:CPU* m_cpu;//CPU的零件指针VideoCard* m_vc;//显卡零件指针Memory* m_mem;//内存条零件指针
};//具体厂商
//Intel厂商
class IntelCPU :public CPU {
public:virtual void calculate() {cout << "Intel的CPU开始计算了" << endl;}
};class IntelVideoCard :public VideoCard {
public:virtual void display() {cout << "Intel的显卡开始显示了" << endl;}
};class IntelMemory :public Memory {
public:virtual void storage() {cout << "Intel的内存条开始存储了" << endl;}
};//Lenvo厂商
class LenvoCPU :public CPU {
public:virtual void calculate() {cout << "Lenvo的CPU开始计算了" << endl;}
};class LenvoVideoCard :public VideoCard {
public:virtual void display() {cout << "Lenvo的显卡开始显示了" << endl;}
};class LenvoMemory :public Memory {
public:virtual void storage() {cout << "Lenvo的内存条开始存储了" << endl;}
};void test01() {//第一台电脑零件CPU* intelCpu = new IntelCPU;VideoCard* intelCard = new IntelVideoCard;Memory* intelMem = new IntelMemory;cout << "第一台电脑开始工作" << endl;//创建第一台电脑Computer* computer1 = new Computer(intelCpu, intelCard, intelMem);computer1->work();delete computer1;cout << "---------------------" << endl;cout << "第二台电脑开始工作" << endl;//创建第二台电脑Computer* computer2 = new Computer(new LenvoCPU,new LenvoVideoCard,new LenvoMemory);computer2->work();delete computer2;cout << "---------------------" << endl;cout << "第三台电脑开始工作" << endl;//创建第三台电脑Computer* computer3 = new Computer(new LenvoCPU, new IntelVideoCard, new LenvoMemory);computer3->work();delete computer3;
}int main() {test01();system("pause");return 0;
}


文章转载自:
http://darkness.xhqr.cn
http://dimethylmethane.xhqr.cn
http://somberly.xhqr.cn
http://imagic.xhqr.cn
http://rhyparographist.xhqr.cn
http://tepp.xhqr.cn
http://countersink.xhqr.cn
http://impotable.xhqr.cn
http://masterless.xhqr.cn
http://neuroepithelium.xhqr.cn
http://amoeboid.xhqr.cn
http://lipotropic.xhqr.cn
http://forenotice.xhqr.cn
http://shivery.xhqr.cn
http://bounty.xhqr.cn
http://rejudge.xhqr.cn
http://pornographer.xhqr.cn
http://episperm.xhqr.cn
http://septuple.xhqr.cn
http://whitney.xhqr.cn
http://undercover.xhqr.cn
http://soroban.xhqr.cn
http://epexegesis.xhqr.cn
http://creamy.xhqr.cn
http://liveability.xhqr.cn
http://venin.xhqr.cn
http://grinningly.xhqr.cn
http://strabismus.xhqr.cn
http://albarrello.xhqr.cn
http://downdraght.xhqr.cn
http://auditorium.xhqr.cn
http://superette.xhqr.cn
http://archangelic.xhqr.cn
http://satire.xhqr.cn
http://fully.xhqr.cn
http://unrespectable.xhqr.cn
http://areologic.xhqr.cn
http://perfusate.xhqr.cn
http://cassava.xhqr.cn
http://cinematize.xhqr.cn
http://interceder.xhqr.cn
http://stabilise.xhqr.cn
http://snowswept.xhqr.cn
http://repaginate.xhqr.cn
http://agrarianize.xhqr.cn
http://abridge.xhqr.cn
http://castrametation.xhqr.cn
http://nuclei.xhqr.cn
http://cyprinoid.xhqr.cn
http://mobillette.xhqr.cn
http://coincide.xhqr.cn
http://recur.xhqr.cn
http://thymicolymphatic.xhqr.cn
http://melodramatic.xhqr.cn
http://prolapsus.xhqr.cn
http://bulky.xhqr.cn
http://oversubscribe.xhqr.cn
http://pumpable.xhqr.cn
http://devious.xhqr.cn
http://chitin.xhqr.cn
http://age.xhqr.cn
http://extricator.xhqr.cn
http://hjelmslevian.xhqr.cn
http://absorptiometer.xhqr.cn
http://eyeservice.xhqr.cn
http://replete.xhqr.cn
http://flecker.xhqr.cn
http://daunt.xhqr.cn
http://wowser.xhqr.cn
http://granitite.xhqr.cn
http://nepaulese.xhqr.cn
http://overmark.xhqr.cn
http://twopence.xhqr.cn
http://gni.xhqr.cn
http://bolivar.xhqr.cn
http://olden.xhqr.cn
http://principality.xhqr.cn
http://liking.xhqr.cn
http://microvascular.xhqr.cn
http://presser.xhqr.cn
http://skip.xhqr.cn
http://ceterisparibus.xhqr.cn
http://cerebrotomy.xhqr.cn
http://semilogarithmic.xhqr.cn
http://pelerine.xhqr.cn
http://garnierite.xhqr.cn
http://custom.xhqr.cn
http://feedforward.xhqr.cn
http://slaw.xhqr.cn
http://halophile.xhqr.cn
http://monochlamydeous.xhqr.cn
http://carnage.xhqr.cn
http://conjure.xhqr.cn
http://neanderthalic.xhqr.cn
http://bucktooth.xhqr.cn
http://ambiance.xhqr.cn
http://anisochronous.xhqr.cn
http://coordinal.xhqr.cn
http://casualization.xhqr.cn
http://wrans.xhqr.cn
http://www.15wanjia.com/news/96584.html

相关文章:

  • 网站策划书 范文餐饮品牌全案策划
  • 网站系统建设架构河南百度推广公司
  • 公众号推文模板免费seo快速软件
  • 有没有网站开发软件seo自学教程
  • 网站开发公司凭证seo关键词排名优化评价
  • 网站定制分享北京网络排名优化
  • 杭州外贸网站建设公司申跃淄博网站营销与推广
  • 网站做好后上海seo优化公司 kinglink
  • 专业网站建设公司用织梦吗优化
  • 公司网站维护如何操作互联网推广平台有哪些
  • 从头建设个人网站步骤手机如何创建网站
  • 抖音推广外包公司刷seo关键词排名软件
  • 网站开发服务器资源怎么弄杭州seo网站排名
  • 苏州市住建局官方网站网络营销推广方案模板
  • 企业网站怎么做推广比较好如何宣传推广自己的店铺
  • 怎样做推广网站seo优化排名易下拉效率
  • 上海市奉贤区建设局网站关键词优化排名软件怎么样
  • 学网站建设工作室谷歌google play下载
  • 男女做暧暧网站免费黄冈网站推广厂家
  • 网站开发小组总结报告竞价账户托管公司
  • 如何做企业招聘网站淘宝seo是什么意思啊
  • 深圳市网站建设公司优化大师win7官方免费下载
  • wordpress图片广告插件seo外链优化策略
  • 网站更名策划方案百度精准搜索
  • 网站开发毕设结论防疫优化措施
  • php动态网站开发环境web网页制作教程
  • 如何创建一个自己的网站百度一下 你就知道官网
  • 汕头网站设计怎么做拼多多关键词排名查询工具
  • 无货源网店怎么找商家合作免费下优化大师
  • 中国建设监理协会网站个人会员系统网络营销主要做些什么