【发布时间】:2011-08-20 15:07:18
【问题描述】:
我有以下代码:
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <conio.h>
#include <cstring>
#include <iomanip>
void swap(long a, long b)
{
long temp;
temp=a;
a=b;
b=temp;
}
int _tmain(int argc, _TCHAR* argv[])
{
int x = 5, y = 3;
cout << x ;
cout << y << endl;
swap(x, y);
cout << x ;
cout << y << endl;
getch();
return 0;
}
程序给出输出:
5 3
3 5
程序实际上交换了值!这是为什么? swap() 的参数不是指针或引用。
(我使用的是 VS 2005)
【问题讨论】:
-
基本上,这是stackoverflow.com/questions/2712076/how-to-use-iterator-in-c/… 的骗子,尽管除非你知道答案,否则你不会知道这一点。
标签: c++ swap argument-dependent-lookup name-lookup