View Single Post
Old 05-25-2004, 04:13 AM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Your comment is correct. Use *.
But you need to pass arguments like:
Code:
int a, b;
	a = 8;
	b = 5;
	swap(&a, &b);
You could do yourself a favor and implement this, wich is much neater:
Code:
void swap(int &a1, int &a2)
{
	if(a1 > a2)
	{
		int temp;
		temp = a1;
		a1 = a2;
		a2 = temp;
	}
}


int main(int argc, char* argv[])
{

	int a, b;
	a = 8;
	b = 5;
	swap(a, b);
	cout<<"a: "<<a<<" b: "<<b<<endl;
	return 0;
}
You could do yourself even another favor: not calling your functions "swap".
Why? Because swap is already defined in the namespace std;
Check this complete code out:
Code:
#include<iostream>

using namespace std;

int main(int argc, char* argv[])
{
	int a, b;
	a = 8;
	b = 5;
	swap(a, b);
	cout<<"a: "<<a<<" b: "<<b<<endl;
	return 0;
}
Better rename your functions to something everyone understands in the given situation in general.
__________________
Valmont is offline   Reply With Quote