I am supposed to write a function that swaps the values of two integers using pointers.While I don't need it to show me the swap values as output, I have done so because I want to see if it works correctly, as I'm new to pointers.
I get the following error:
" [Linker error] undefined reference to `SwapIntegers(int*, int*)' ld returned 1 exit status "
#include <iostream>
#include <stdlib.h> // pause screen after completion
using namespace std;
int SwapIntegers(int *p1, int *p2);
int main()
{
int x,y; // variable declaration
int *px = &x;
int *py = &y;
SwapIntegers (px, py);
cout << "x is " << px << endl
<< "y is " << py << endl;
system("pause"); //stop the screen
} // end main
// swap function
int SwapIntegers (int px, int py)
{
cout << "Enter first integer: ";
cin >> px;
cout << "Enter second integer: ";
cin >> py;
cout << "x is: " << px << " before swapping" << endl
<< "y is: " << py << " before swapping" << endl;
px ^= py;
py ^= px;
px ^= py;
return(px, py);
} // end function swap
I get the following error:
" [Linker error] undefined reference to `SwapIntegers(int*, int*)' ld returned 1 exit status "