class parent {
public:
void f() { cout << "parent f()" << endl; }
void f(int i) { cout << "parent f(int i)" << endl; }
}; class child :public parent {
};
int main() { child a;
a.f();
a.f();
return ;
}

父类中发生了重载。

子类中如果没有定义名字冲突的成员函数,这时候,父类中的两个函数都可以访问。

class child2 :public parent {
public:
void f() {
cout << "child f()" << endl;
}
};
int main() { child2 a; parent *p = &a;
child2 *c = &a; a.f(); //child f()
a.parent::f(); //parent f()
a.parent::f(); //parent f(2) p->f(); // parent f()
p->f(); // parent f(2) c->f(); // child f()
// c->f(2); illegal return ;
}

有冲突的时候,a只能直接访问自己定义的这个。

父类中的f必须通过a.parent::f这样的方式访问。这三个是并存的。

加了virtual以后呢?

最新文章

  1. 自定义样式 实现文件控件input[type=&#39;file&#39;]
  2. Extjs插入图片
  3. [eclipse]改项目名称后tomcat连接问题解决方法
  4. Cocos2d-x 学习资料推荐
  5. C#实现的ReplaceFirst和ReplaceLast
  6. 通过Html5的postMessage和onMessage方法实现跨域跨文档请求访问
  7. java日期详解
  8. Cocos2d-swift V3.x 中的update方法
  9. iframe与主框架跨域相互访问方法
  10. Android.os.SystemClock
  11. minicom 安装 查看串口
  12. editplus来编写html
  13. Python Word2Vec使用训练好的模型生成词向量
  14. scheme 之门
  15. Spring注解方式配置说明
  16. POJ 2195 Going Home(费用流)
  17. 在iOS 7中使用storyboard(part 1)
  18. linux-android(任务处理)
  19. 马尔科夫毯(Markov Blanket)
  20. [Linux] 服务器镜像定时备份解决方案 crontab+rsync+flock

热门文章

  1. [UE4]通过IP地址加入游戏
  2. 做好平衡有多难?谈MMO的职业设计
  3. CRM 2016 设置字体颜色
  4. _mysql.c(42) : fatal error C1083: Cannot open include file: &#39;config-win.h&#39;:问题的解决
  5. 第11章 拾遗4:IPv6(2)_给计算机配置IPv6地址
  6. elasticsearch 外网访问9200端口访问
  7. Android 硬编码
  8. tips:Java中的switch的选择因子
  9. 网络爬虫2:使用crawler4j爬取网络内容
  10. 查看Selinux和关闭Selinux