/*
* 编译时的多态.cpp
*
* Created on: 2013-10-21
* Author: Administrator
*/
#include<iostream>
using namespace std;
void func()
{
cout << "func()函数没有传入参数\n";
}
void func(int a)
{
cout << "func(int a )函数传入参数是:";
cout << "a=" << a << endl;
}
void func(int b, char c)
{
cout << "func(int a )函数传入数值和字符是:";
cout << "b=" << b << ", c = "<< c << endl;
}
void func(int &d, int e)
{
cout << "func(int &d, int e )函数传入的引用和数值是:";
cout << "d=" << d << ", e = "<< e << endl;
d = d + e;
}
void func(int a[], int n)
{
cout << "func(int a[], int n )函数传入数组arr的首地址,各元素是:\n";
int i ;
for (i = 0; i < n; i++)
{
cout << "[" << i << "]=" << a[i] << " , ";
}
cout << endl;
}
int main(void)
{
int arr[] = {12, 23, 34, 45, 56, 67};
int n = 6, d= 78, e = 89;
cout << "这里是编译时金矿举例: " << endl;
func();
func(3);
func(5,'A');
func(d,e);
cout << "调用func(int &d, int e)后 d = " << d << ", e = " << e << endl;
func(arr,n);
return 0;
}
/*
* 输出:
* 这里是编译时金矿举例:
* func()函数没有传入参数
* func(int a )函数传入参数是:a=3
* func(int a )函数传入数值和字符是:b=5, c = A
* func(int &d, int e )函数传入的引用和数值是:d=78, e = 89
* 调用func(int &d, int e)后 d = 167, e = 89
* func(int a[], int n )函数传入数组arr的首地址,各元素是:
* [0]=12 , [1]=23 , [2]=34 , [3]=45 , [4]=56 , [5]=67 ,
*
* 在上述程序中,函数"func(int &d, int e)" 的参数分别是引用传递和值班传递,帮有函数
* 调用返回后d的值班改变为167,而变量e未变; 函数“func(int a[], int n)” 的参数
* 传递分别是地址传递和值传递
*/
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。