6.2 函数多态

Posted: March 25, 2011 in C++

/*函数重载或函数多态可以使函数”同名不同类”*/

#include <iostream>

int Plus1(int a);
long Plus1(long b);
double Plus1(double c);
float Plus1(float d);

using namespace std;

void main()
{
                int a=1;
                long b=50;
                double c=6.12e20;
               float d=5.23f;

                int a1;
                long b1;
                double c1;
                float d1;

                a1=Plus1(a);cout<<“a1=”<<a1<<endl;
                b1=Plus1(b);cout<<“b1=”<<b1<<endl;
                c1=Plus1(c);cout<<“c1=”<<c1<<endl;
                d1=Plus1(d);cout<<“d1=”<<d1<<endl;

}

int Plus1(int a)
{
                return(a+1); 
}

long Plus1(long b)
{
                return(b+1); 
}

double Plus1(double c)
{
                return(c+1); 
}

float Plus1(float d)
{
                return(d+1); 
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s