笔试题 -- 重载、重写(覆盖)、隐藏

网友投稿 853 2022-11-18

笔试题 -- 重载、重写(覆盖)、隐藏

笔试题 -- 重载、重写(覆盖)、隐藏

#include #include #include using namespace std;class A{public: //重载 int getval() { return 1; } int getval(int a) { return a; } virtual show() { cout << "show1" << endl; } int display() { cout << "display()" << endl; }};class B:public A{public: int getval(int a,int b) { return a+b; } show() { cout << "show2" << endl; }};int main(){ //重载 /* 1.函数名相同 2.参数类型或个数不同(返回值无影响) 3.同一访问区域内(同一类里) */ A a; cout << "a.getval(7) = " <

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:笔试题 -- vector内存空间释放及vector数据清空
下一篇:对数组名的理解
相关文章

 发表评论

暂时没有评论,来抢沙发吧~