Why is it swapping?

So I was going to write a small program that swaps 2 numbers values. But in the function, I don't have to write any code apart inside the function and it swaps.

Can someone explain to me why it swapping for?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;

void swap(int* a, int* b)
{
}

int main()
{
	int a = 5;
	int b = 10;

	cout << "A: " << a << " B: " << b << endl;
	swap(a, b);
	cout << "A: " << a << " B: " << b << endl;

	cin.get();
	return 0;
}
You're not calling your own swap function. You're calling a different one that is part of C++ and has been included by the header file you've included.

Oh, LOL! My mistake then, thanks.
This is why people often discourage use of using namespace std; ;)
Haha yeah, normally I don't even use namespaces.. was being lazy and it caught me out. :P
Topic archived. No new replies allowed.