C++学习------过载多态的例子
2007-06-16 11:45
295 查看
#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++多态的几个小例子
- C++学习------参数多态的例子
- C++学习------强制多态的例子
- C++学习------包含多态的例子
- C++学习之多态的实现
- C++的多态例子
- c/c++中指针学习的两个绝好例子
- C++简单学习(Part2_lecture 8)(继承、重载、多态、虚函数)
- 通过例子学习Lua(6)--C/C++中用Lua函数
- c/c++中指针学习的两个绝好例子
- C++学习之多态及重载(overload),覆盖(override),隐藏(hide)的区别
- c/c++中指针学习的两个绝好例子
- C++学习笔记之多态(虚函数)
- C++ opencv快速例子学习——读图显示
- 通过例子学习Lua(6)----C/C++中用Lua函数
- c++学习例子静态链表ListEntry
- 嵌入式开发之C++基础学习笔记4--面向对象封装继承多态
- c++模板类学习--例子编译可能有问题【注】
- C++学习手记四:继承和多态
- c++学习笔记--虚函数和多态的重新认识