多态--过载多态
来源:互联网 发布:本科生发表论文 知乎 编辑:程序博客网 时间:2024/05/01 16:51
#include<iostream.h>
//演示过载多态。
class OverLoad
{
public:
void test()
{
cout<<"test()被执行"<<endl;;
}
void test(int a)
{
cout<<"test(int a)被执行"<<endl;;
}
void test(char a)
{
cout<<"test(char a)被执行"<<endl;
}
void test(int a,double x)
{
cout<<"test(int a,double x)被执行"<<endl;
}
/*
void test(int a)
{
cout<<"test(int a)被执行";
}
与
void test(int b)
{
cout<<"test(int b)被执行";
}
不能构成多态,它们只是变量名不同一样,实际上是同一个函数
*/
};
void main()
{
OverLoad OL;
OL.test();
OL.test('A');//若写为OL.test(0x65);则调用test(int a)函数
OL.test(12);
OL.test(5,5.0);
}
//演示过载多态。
class OverLoad
{
public:
void test()
{
cout<<"test()被执行"<<endl;;
}
void test(int a)
{
cout<<"test(int a)被执行"<<endl;;
}
void test(char a)
{
cout<<"test(char a)被执行"<<endl;
}
void test(int a,double x)
{
cout<<"test(int a,double x)被执行"<<endl;
}
/*
void test(int a)
{
cout<<"test(int a)被执行";
}
与
void test(int b)
{
cout<<"test(int b)被执行";
}
不能构成多态,它们只是变量名不同一样,实际上是同一个函数
*/
};
void main()
{
OverLoad OL;
OL.test();
OL.test('A');//若写为OL.test(0x65);则调用test(int a)函数
OL.test(12);
OL.test(5,5.0);
}
- 多态--过载多态
- C++学习------过载多态的例子
- 过载
- 参数多态、包含多态、过载多态和强制多态
- 【语言基础】参数多态、包含多态、过载多态和强制多态
- 多态分类-强制多态,参数多态,过载多态,包含多态的理解
- 过载保护
- 过载保护
- 过载保护
- 过载&覆盖
- 过载保护
- ”过载“和“覆盖”
- 主类型过载求解
- 浅谈过载保护
- 浅谈过载保护
- 浅谈过载保护
- 浅谈过载保护
- java 主类型过载
- 分块查找
- 索引查找
- 上周面试
- 多态--包含多态
- VC的悲哀
- 多态--过载多态
- 制作CHM帮助文件遇到的问题及解决方法
- 多态--强制多态
- 昂首阔步 从BC编译器走向VC编译器
- 网站小功能
- 23种设计模式开幕篇------简单工厂模式
- 独家:Windows配置管理之我见
- TomCat 5.5 配置MSSQL数据库连接池
- Vista系统给微软的七大教训