//演示過載多態。
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);
}