a test program for polymophism in c++
来源:互联网 发布:华西医院网络门诊 编辑:程序博客网 时间:2024/05/24 06:38
#include<iostream>
using namespace std;
class B
{
public:
virtual void f1() const
{
cout<<"B::f1"<<endl;
}
virtual void f2() const
{
cout<<"B::f2"<<endl;
}
};
class D: public B
{
public:
void f1() const
{
cout<<"D::f1"<<endl;
}
virtual void f3() const
{
cout<<"D::f3"<<endl;
}
};
void main()
{
D d;
//pointer and reference both can achieve polymophism
B& rb=d;
rb.f1(); //output: D::f1
rb.B::f1(); //output: B::f1
B* pb = &d;
pb->f1(); //output: D::f1
pb->B::f1(); //output: B::f1
char ch;//pause
cin>>ch;
}
Output:
If D::f1 changed to
void f1()
{
cout<<"D::f1"<<endl;
}
That is delete the const, then the result is:
This is because Constness is a part of function signature.
- a test program for polymophism in c++
- What is the best free memory leak detector for a C/C++ program and its plug-in DLLs
- What is the best free memory leak detector for a C/C++ program and its plug-in DLLs
- CUnit - A Unit Test Framework For C
- A test .c file for aes
- C Program to sleep for millisecond in windows, linux
- You Can Program in C++: A Programmer's Introduction
- You Can Program in C++: A Programmer's Introduction
- A Linux serial port test program
- Learning Perl: 8.9. A Pattern Test Program
- A Linux serial port test program
- Just for a test!...
- (HTTP) Streaming a video using a program in C/C++ under Linux(轉載)
- Memory partition in C program
- lseek() sample program in C
- C program for quick sort
- C program for 折半查找
- Generic Makefile for C program
- jsp常用的指令与标签
- 我的军训生活
- 围剿Viking、专杀工具的较量——继初遇Worm.Viking.dy
- 成功法则--热情
- 掌握 Ajax
- a test program for polymophism in c++
- 面向 Java 开发人员的 Ajax
- 杂谈 我的那几年 与计算机技术相关 回顾 20061102
- 蓝牙鼠标实用--革命尚未成功,蓝牙仍须努力
- python几个内置函数之-filter,map,reduce
- SWT绘图需要注意的一个问题
- .NET 线程池
- 硬 盘 的 秘 密
- 今天面试了两个很大差距的人