C++父类子类中虚函数的使用
来源:互联网 发布:udid授权软件 编辑:程序博客网 时间:2024/06/05 18:01
构造函数不能是虚函数,因为在调用构造函数创建对象时,构造函数必须是确定的,所以构造函数不能是虚函数。
析构函数可以是虚函数。
1.父类Father.h:
Father.cpp
2.子类Child.h:
Child.cpp
3.测试类Test.cpp
4.输出结果:
Father is called. count = 1
Father::getCount() count = 1
father1 count = 1
~Father is called.
************** father1 end *****************
Father is called. count = 1
Child is called. count = 2, age = 20
Child::getCount() count = 2
father2 count = 2
~Child is called.
~Father is called.
************** father2 end *****************
Father is called. count = 1
Child is called. count = 2, age = 20
Child::getCount() count = 2
child count = 2
Child::getAge() age = 20
child age = 20
~Child is called.
~Father is called.
************** child end *****************
原文地址:http://blog.csdn.net/ameyume/article/details/6285902
- C++父类子类中虚函数的使用
- C++父类子类中虚函数的使用
- C语言使用技巧3:C++中子类调用父类重载函数的方法
- 在C 中子类继承和调用父类的构造函数方法
- 【C++】子类在重写虚函数时,会覆盖父类的函数
- C++:从子类访问父类的私有函数
- 子类重载父类的虚函数
- 通过虚函数继承,父类调用子类中函数
- c++,父类引用指向子类对象,虚函数
- c++,父类引用指向子类对象,虚函数
- c++中 子类父类的构造函数调用顺序
- Java中子类和父类的构造函数?
- 子类使用构造函数初始化父类的私有数据
- [C++]子类的构造函数
- c#中子类使用被隐藏的父类方法
- 在子类的构造函数中调用虚函数
- C++ 继承中子类与父类虚函数入栈顺序 及父类私有虚函数的调用方式
- [c++]子类私有的虚函数,多态问题
- tensorflow 中Graphs的相关文档
- Java并发容器和框架(五)
- java设计模式之静态代理和动态代理
- LeetCode-171. Excel Sheet Column Number
- Runtime.getRuntime().exec() 输出流阻塞的解决方法
- C++父类子类中虚函数的使用
- Java 之 final 关键字
- PAT乙级1036 跟奥巴马一起编程
- Python爬取网站信息出现Errno 10054
- Javascript中的深拷贝与浅拷贝
- 程序员发展之路
- GetVersionEx函数
- SQL 到 mongo的对应表
- boost::format常用用法