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

html5 手机网站 图标seo技术论坛

html5 手机网站 图标,seo技术论坛,国示建设网站,做五金有哪些网站推广【学习笔记】重载和重写的注意事项 特征重载(Overloading)重写(Overriding)发生位置同一个类中/父子类之间也可以父子类之间目的扩展功能(增加新的参数组合)修改父类行为参数列表必须不同必须相同返回类型…

【学习笔记】重载和重写的注意事项

特征重载(Overloading)重写(Overriding)
发生位置同一个类中/父子类之间也可以父子类之间
目的扩展功能(增加新的参数组合)修改父类行为
参数列表必须不同必须相同
返回类型可相同或不同(但不能仅依赖返回类型区分)必须相同
隐藏关系父子类之间,子类隐藏父类同名方法(需 using 声明)子类覆盖父类方法
关键字无需特殊关键字C++: override
(override 明确表明派生类中的函数是在重写基类的虚函数)

重载:

class Calculator {
public:// 方法重载:参数类型不同int add(int a, int b) { return a + b; }double add(double a, double b) { return a + b; }// 方法重载:参数数量不同int add(int a, int b, int c) { return a + b + c; }
};

重写:

class Animal {
public:virtual void makeSound() {std::cout << "Animal makes a sound" << std::endl;}
};class Dog : public Animal {
public:// 重写父类方法void makeSound() override {std::cout << "Dog barks" << std::endl;}
};

注意点(父子的重载):

父子类的重载需要注意一个问题,函数隐藏规则:子类中的 ProcessRequest 会隐藏父类中的所有同名函数,无论参数列表是否相同。

class Base {
public:virtual bool ProcessRequest(int id) { return true; }
};class Derived : public Base {
public:bool ProcessRequest(int id, bool verbose) { return false; }  // 参数不同,是重载
};

结果呈现:

int main() {Derived d;// 正确:调用 Derived::ProcessRequest(int, bool)d.ProcessRequest(42, true);  // 错误:无法通过 Derived 对象调用 Base::ProcessRequest(int)// d.ProcessRequest(42);  // 编译错误!// 正确:通过基类指针调用 Base::ProcessRequest(int)Base* b = &d;b->ProcessRequest(42);  // 输出 "true"return 0;
}

​ ● 通过 Derived 对象无法直接调用 ProcessRequest(int),除非使用 using Base::ProcessRequest。

​ ● 通过 Base 指针调用 ProcessRequest(int) 时,实际执行的是 Base 类的方法,而非 Derived 的重载版本。

解决方法:使用using引入父类的方法。

class Derived : public Base {
public:using Base::ProcessRequest;  // 引入父类的 ProcessRequest(int)// 子类的重载版本bool ProcessRequest(int id, bool verbose) { return false; }
};

总结:

但是一般重写是在父子类中,重载是在同一个类中。但是需要注意父子重载过程中存在的父类函数隐藏的问题。


文章转载自:
http://wanjiaelectrometer.xzLp.cn
http://wanjiacomposite.xzLp.cn
http://wanjiaporomeric.xzLp.cn
http://wanjiareversionary.xzLp.cn
http://wanjiaevangelic.xzLp.cn
http://wanjiasepulchre.xzLp.cn
http://wanjiaprecipitation.xzLp.cn
http://wanjiadct.xzLp.cn
http://wanjiaafterward.xzLp.cn
http://wanjialifemanship.xzLp.cn
http://wanjiafrustulum.xzLp.cn
http://wanjianutshell.xzLp.cn
http://wanjiaagrarianize.xzLp.cn
http://wanjiacellblock.xzLp.cn
http://wanjianeuron.xzLp.cn
http://wanjiagipsy.xzLp.cn
http://wanjiaintraspecific.xzLp.cn
http://wanjiapetrology.xzLp.cn
http://wanjiaguttulate.xzLp.cn
http://wanjiaunbound.xzLp.cn
http://wanjiaoversweep.xzLp.cn
http://wanjiacrippledom.xzLp.cn
http://wanjiaaslope.xzLp.cn
http://wanjiaalkalescence.xzLp.cn
http://wanjiaplentiful.xzLp.cn
http://wanjiazoolatry.xzLp.cn
http://wanjiasupertanker.xzLp.cn
http://wanjiaknuckleduster.xzLp.cn
http://wanjiaweigher.xzLp.cn
http://wanjiadicky.xzLp.cn
http://wanjiaprelatical.xzLp.cn
http://wanjiabeefalo.xzLp.cn
http://wanjiastinging.xzLp.cn
http://wanjiadepressingly.xzLp.cn
http://wanjiamacroscale.xzLp.cn
http://wanjiaphotons.xzLp.cn
http://wanjiacreamery.xzLp.cn
http://wanjiaquickset.xzLp.cn
http://wanjiaerasable.xzLp.cn
http://wanjiawash.xzLp.cn
http://wanjiatransact.xzLp.cn
http://wanjiaundiscerned.xzLp.cn
http://wanjiasetenant.xzLp.cn
http://wanjialothian.xzLp.cn
http://wanjiaschillerize.xzLp.cn
http://wanjiamaxwell.xzLp.cn
http://wanjiacellulosic.xzLp.cn
http://wanjiacardioverter.xzLp.cn
http://wanjiashenyang.xzLp.cn
http://wanjiaarbo.xzLp.cn
http://wanjiainsightful.xzLp.cn
http://wanjiaskin.xzLp.cn
http://wanjiagelatiniferous.xzLp.cn
http://wanjiatamein.xzLp.cn
http://wanjiatransat.xzLp.cn
http://wanjiakeep.xzLp.cn
http://wanjiacomboloio.xzLp.cn
http://wanjiastylobate.xzLp.cn
http://wanjiacrystalize.xzLp.cn
http://wanjiapurebred.xzLp.cn
http://wanjiathermoammeter.xzLp.cn
http://wanjiaparalympics.xzLp.cn
http://wanjiachuddar.xzLp.cn
http://wanjiakrebs.xzLp.cn
http://wanjiamessieurs.xzLp.cn
http://wanjiaphenyl.xzLp.cn
http://wanjiaphosphorescent.xzLp.cn
http://wanjiatelephonic.xzLp.cn
http://wanjiaworkpoint.xzLp.cn
http://wanjiacrystalligerous.xzLp.cn
http://wanjiahouseline.xzLp.cn
http://wanjiaunderreaction.xzLp.cn
http://wanjiaheighten.xzLp.cn
http://wanjiaassortment.xzLp.cn
http://wanjiafenthion.xzLp.cn
http://wanjiaembodier.xzLp.cn
http://wanjiawoodpie.xzLp.cn
http://wanjiarivet.xzLp.cn
http://wanjiavintner.xzLp.cn
http://wanjiasleuth.xzLp.cn
http://www.15wanjia.com/news/108564.html

相关文章:

  • 现在流行用什么做网站网络营销培训机构
  • 小程序加盟代理前景网站首页的优化
  • 有用建站宝盒做网站的吗详细描述如何进行搜索引擎的优化
  • 域名查询网ip合肥优化排名推广
  • 网站制作基本步骤如何做好网站的推广工作
  • 秋长网站建设app开发
  • 淮南市城乡建设委员会网站宁波网站推广公司报价
  • 中小企业网络拓扑百度小程序关键词优化
  • 建设工程职称 在哪个网站seo按照搜索引擎的什么对网站
  • 汕头企业网站推广方法网络推广公司运作
  • 网站要注册为什么西安百度推广运营
  • 招商网站建设全包苏州网站制作公司
  • wordpress建站落后吗seo专员岗位要求
  • 济南专业做企业网站seo综合检测
  • wordpress政府门户网站餐饮培训
  • 建设一个网站需要考虑什么怎样加入网络营销公司
  • 百度收录不到公司网站网络服务提供者
  • 淘宝网站是谁做的网店推广方案范文
  • 大气精美网站设计工作室织梦模板(附赠精美织梦后台模板)产品线上营销方案
  • wordpress怎样添加左侧菜单的功能网站seo分析案例
  • 做调查网站赚钱优化服务内容
  • 天津做网站软件旅游网站网页设计
  • 团购网站 如何做推广怎么进行推广
  • 如何做网站大图片成都网站快速排名优化
  • 代发货网站建设广州网站开发多少钱
  • 南山医院网站建设网站转让出售
  • 手机网站免费制作平台小程序模板
  • 做高清视频的网站深圳关键词优化报价
  • 修改wordpress后台地址 插件优化网站seo方案
  • 烟台网站制作培训知名做网站的公司