On Mon, Feb 16, 2009 at 7:29 PM, e211 <e...@hotmail.com> wrote: > > //The following code works and there is no way it should. Seems like a bug > someone put in on purpose > > #include <iostream> > using namespace std; > > void swap(int *x, int *y) > { > int temp; > temp = *x; > *x = *y; > *y = temp; > } > > int main() > { > int x = 10; > int y = 20; > cout << x << " " << y << endl; > swap(x,y); //how does this work, there is no way this should compile > and > run and actually work > cout << x << " " << y << endl; > }
iostream is bringing in the definition of std::swap which takes a reference. And you have a "using namespace std;" there. Thanks, Andrew Pinski