#include <iostream>
class Person{
public:
virtual void say(){
std::cout<<"person"<<std::endl;
}
};
class Student:public Person{
public:
void say(){
std::cout<<"student"<<std::endl;
}
};
int main(){
Person per;
Student stud;
per.say();
stud.say();
//传递对象
per = stud;
per.say();
//指针
Person *pPtr = &stud;
pPtr->say();
//引用
Person &pRef = stud;
pRef.say();
}

1. 基类中用virtual关键字表明方法
2. 采用父类的引用和指针调用多态方法,父类对象本身不能实现多态

最新文章

  1. ZendStudio13 PHP调试环境快速配置
  2. Win10 UWP开发中的重复性静态UI绘制小技巧 1
  3. 分布式日志1 用c#的队列写日志
  4. java 关键字
  5. 【原创】Mac上编译Hadoop1.0.3出现的一些问题
  6. CentOS 6.4 64位 搭建MySQL-Cluster 7.3.8 集群
  7. CListCtrl 的应用
  8. HDU 1071 - The area
  9. poj3094---对字符串的处理
  10. hdu 2824 The Euler function(欧拉函数)
  11. (二)、Struts第二天
  12. Halloc内存分配器
  13. Go 延迟函数 defer 详解
  14. request 获取body内容
  15. Cocos Creator 动态改变sprite图片
  16. json和jquery中的ajax
  17. mysql查询时间段内的数据
  18. CSS规范 - 典型错误--(来自网易)
  19. JS获取当前项目名
  20. 简述Dubbo

热门文章

  1. html中文件类型的accept属性有哪些
  2. 12 nginx URL 重写 ecshop案例
  3. JavaWeb学习总结第四篇--Servlet开发
  4. ASP.NET动态网站制作(8)-- JS(3)
  5. Grails 简要
  6. HDU 1452 Happy 2004(唯一分解定理)
  7. 再看GS接包过程
  8. EasyPusher华为手机直播推流硬编码[OMX.IMG.TOPAZ.Encoder] failed to set input port definition parameters.
  9. 前端mvc组合框架
  10. python使用记录