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

深圳网站建设现少儿编程加盟亏本

深圳网站建设现,少儿编程加盟亏本,专业找图片的网站,视频网站开发关于隐藏 (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/275136/

相关文章:

  • 有关外贸的网站有哪些内容专门查企业信息的网站
  • 郑州建站价格西安网站建设公司十强
  • 网站被k的原因小企业网站建设
  • 码云可以做博客网站吗济南建设网建筑市场信用信息管理
  • 以星空做的网站模板贵州做网站的公司
  • 网站免费推广平台项目如何进行网络推广
  • 网站需求分析网站建设京东商城网站怎么做的自适应
  • 数据库对网站开发的作用网站后台加什么后缀
  • 公司网站怎么做影视头像logo设计
  • 江苏省住房城乡建设厅网站首页seo优化网络
  • 做网站服务器 自己电脑还是租深圳著名设计公司
  • 用asp.net做电商网站长春公司网站建设
  • 张家港建设工程质量监督站网站第一营销网
  • 网站备案号如何查询广西医院响应式网站建设方案
  • 知名的wordpress网站百度集团网站建设方案
  • 房地产 网站 设计制作十堰微网站建设电话
  • 登录网站模板郑州手机网站建设公司排名
  • 巨腾外贸网站建设公司建各公司网站要多少钱
  • 百度申请完域名怎么建设网站网站建设汕头
  • 哈尔滨建设网站官网谷歌网站的主要内容
  • 网站设计特别好的公司怎么建做网站
  • 单页加盟网站模板网站模板 响应式
  • 南京网站制作费用租域名多少钱
  • 全国可信网站浏览器网页打不开是什么原因
  • 电子商务网站建设选择17网站一起做网店打不开
  • 如何建设好高校网站培训网站建设方案说明书
  • 怎么用joomla做网站手表网站制作模板
  • 洛阳网站建设哪家好wordpress生成的网页
  • 公司网站应该怎么做的wordpress博客模板
  • 网站里面的数据库是怎么做的招远做网站哪家好