C++源码:重载的应用实例

//   C++源码:Example for "OVERLOAD"  重载的应用实例

#include <iostream>
using namespace std;

int   max(int a,int b);
float max(float a,float b);

int max(int a,int b)
 {
   cout<<" \n Now in int max(int a,int b)";
   if (a>b)
     return a ;
     else
     return b;
 }

float max(float a,float b)
 {
  cout<<"\n Now in  float max(float a,float b)\n !";
  if (a>b)
     return a;
     else
     return b;
 }

main()
{
  int x=1,y=1;
  float xx=1.0,yy=1.0;
  {
    cout<<"\007"<<"Please input the INT vallue of X and Y:"<<flush;
    cin>>x>>y;
    cout<<"\nX="<<x<<"\nY="<<y;
    cout<<"\n\n Now,after  max()="<<max(x,y);

cout<<"\007"<<"\nPlease input the FLOAT vallue \n of XX and YY:"<<flush;
    cin>>xx>>yy;
    cout<<"\n\n Now,after  max()="<<max(xx,yy);
  }
}

(0)

相关推荐