c++之默认参数
void swap( int val1, int val2, ofstream &ofil ) { ofil << "swap( " << val1 << ", " << val2 << " )\n"; int temp = val1; val1 = val2; val2 = temp; ofil << "after swap(): val1 " << val1 << " val2: " << val2 << "\n"; } void swap( int val1, int val2, ofstream *ofil = 0 ) { if ( ofil ) (*ofil) << "swap( " << val1 << ", " << val2 << " )\n"; int temp = val1; val1 = val2; val2 = temp; if ( ofil ) (*ofil) << "after swap(): val1 " << val1 << " val2: " << val2 << "\n"; }