undefined reference to function

hi all
i am new to c++ programming
i wrote the following code to : "swap 2 integers using reference
variables as arguments in the function"

#include<iostream>
using namespace std;
void swap(int x, int y);
int main()
{
int a,b;
cout<<"enter two nos.\n";
cin>>a>>b;
swap(a,b);
return 0;
}
void swap(int &x,int &y)
{
int z;
z=x;
x=y;
y=z;
cout<<"first no is "<<x<<"\nsecond is "<<y;
}


when i compiled this i got this error :

abhi@abhi-desktop:~$ g++ ex3-1.cc
/tmp/ccwVyPnQ.o: In function `main':
ex3-1.cc:(.text+0x139): undefined reference to `swap(int, int)'
collect2: ld returned 1 exit status


please tell me what fault have i made
thanks
The declaration of the "swap" function is void swap(int x, int y);
But after that you have void swap(int &x,int &y)

Remove the reference from it or add it to the declaration also, they must be the same.
thanks it worked
Topic archived. No new replies allowed.