// 默认实参.cpp : Defines the entry point for the console application.
  //

  #include "stdafx.h"
  #include <iostream>
  using namespace std;

  void  showVolume(int length, int width = 1, int height = 1) ;

  int main(int argc, char* argv[])
  {
     showVolume(4,6,8);
     showVolume(4,6);
     showVolume(4);

     return 0;
  }

  //默认实参只能被定义一次
  //
  void showVolume(int length, int width, int height) {
     cout <<"\nVolume of a bow with \n"
         <<"Lenght = " << length <<", Width = " << width <<" and Height = " << height
         <<" is " << length * width * height <<endl;
  }

 

 

//任何使用默认实参的地方也可以用重载来完成,不过使用默认实参要比使用重载更简单。

 

 

 

 posted on 2012-04-12 22:04  飞翔@骑士  阅读(92)  评论(0)    收藏  举报