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";
}

  

posted @ 2019-07-21 14:25  wdliming  阅读(335)  评论(0编辑  收藏  举报