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

集团定制网站建设公司四川 网站建设

集团定制网站建设公司,四川 网站建设,wordpress自动文章排版,做底单的网站关于隐藏 (hidden) 假如继承以后&#xff0c;子类出现父类同名函数&#xff0c; 即使参数的形式不同&#xff0c; 也会导致父类的函数隐藏&#xff0c; 不参与函数匹配&#xff0c;不能使用。 这个链接讲的不错。https://zhuanlan.zhihu.com/p/575423511 #include <iostrea…

关于隐藏 (hidden)
假如继承以后,子类出现父类同名函数, 即使参数的形式不同, 也会导致父类的函数隐藏, 不参与函数匹配,不能使用。
这个链接讲的不错。https://zhuanlan.zhihu.com/p/575423511

#include <iostream>
using namespace std;
class Vehicle {
public:void accelerate() { cout << "Increasing speed: "; }
};
class Aeroplane : public Vehicle {public:void accelerate(int height) {cout << "Accelerating at a height of: " << height;}
};int main() {Aeroplane plane;plane.accelerate(1000);plane.accelerate();  //这里出错!main.cpp:17:25: error: no matching function for call to ‘Aeroplane::accelerate()’cout << endl;
}

如果子类的instance就是想调用父类的同名不同参的函数呢?方法有两个。

  1. 显式调用父类版本的函数
    b.A::func(); // 显式指定父类版本,合法
    #include
    using namespace std;
    class Vehicle {
    public:
    void accelerate() { cout << "Increasing speed: "; }
    };
    class Aeroplane : public Vehicle {
    public:
    void accelerate(int height) {
    cout << "Accelerating at a height of: " << height;
    }
    };

int main() {
Aeroplane plane;
plane.accelerate(1000);
plane.Vehicle::accelerate();
cout << endl;
}

  1. 用using
    using A::func; // 解开父类重载函数的默认隐藏。
#include <iostream>
using namespace std;
class Vehicle {
public:void accelerate() { cout << "Increasing speed: "; }
};
class Aeroplane : public Vehicle {public:using Vehicle::accelerate;void accelerate(int height) {cout << "Accelerating at a height of: " << height;}
};int main() {Aeroplane plane;plane.accelerate(1000);plane.accelerate();cout << endl;
}
  1. 当然也可以直接在子类的函数里面调用
class Aeroplane : public Vehicle {public:void accelerate(int height) {Vehicle::accelerate();  cout << "Accelerating at a height of: " << height;}
};

关于overload

关于override
如果不用virtual,怎么实现多态呢?可以用cast。但是对不同子类的object都要cast到对应的子类类型,显然很不方便。
static_cast<Circle *>(s)->draw();

#include <iostream>
#include <vector>using namespace std;class Shape {
public:void draw() { cout << "Drawing a generic shape...\n"; }
};class Circle: public Shape {
public:void draw() { cout << "Drawing a circle...\n"; }
};int main() {vector<Shape *> shapes;      // Vector of pointers to Shape instances// Create a pointer to a child class of Shape and append it to the vector shapes.push_back(new Circle);for (auto s: shapes)static_cast<Circle *>(s)->draw();      for (auto s : shapes)       // Release allocated memorydelete s;
}
http://www.yayakq.cn/news/717021/

相关文章:

  • 六安市 网站集约化建设黄冈工程造价信息网
  • 创建官方网站wap网站asp源码
  • 女装网站建设计划书软件开发app制作公司
  • 用源码网站好优化吗做网站 页面自适应
  • 学校如何建设网站首页网站开发资料
  • 哪个网站服务器比较好手机商城系统总结
  • 有谁会设制网站郑州工装定制公司
  • 站长工具端口检测图片网站源码asp
  • 物流企业的网站模板宿迁专业网站建设公司
  • 广告商网站建设番禺网站建设公司
  • 网站空间便宜免费咨询律师问题
  • 咨询公司网站网页制作怎么添加视频
  • PHP网站新闻发布怎么做wordpress目录导航主题
  • 计算机网络应用主要学什么郑州网站建设搜索优化
  • 福田营销型网站建站推广外包同城招聘工作信息附近
  • 最新网站开发软件中国黄页网
  • 在线医疗网站建设酒店协会网站集静态模板
  • 厦门安能建设品牌网站建设网络科技网站设计
  • 陈铭生怎么死的嘉兴优化公司
  • 垂直电商网站如何做内容运营南通做网站需要多少钱
  • 网站推广网站关键词排名怎么做模板建站费用
  • 潍坊公司注册网站许昌那有做网站
  • 商丘做手机做网站想学网站建设优化去哪
  • 网站跳转怎么做文山知名网站建设联系电话
  • 长沙网站建站推广点击排名优化
  • 摄影看图网站兄弟们给个能用的网站
  • 深圳官网多产品的网站怎么做seo
  • 营销型网站单页工程施工公司
  • 网站建设和管理规则国外英语写作网站
  • 郴州网站建设解决方案网页设计代码如何写实训报告过程