Can't assign int* to int?

As the title state I don't understand why temp can't equal to whatever the contents of b is pointing to?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void swap (int* a, int* b) 
{
  int temp = 0; 
  if (a > b)
    {
       temp = b; // get error on this line 
       a = b;
       temp = a; 
    }
}
 int main ()
{
int a; 
int b; 
cout << "Please insert integer a."; 
cin >> a; 
cout << "Please insert integer b.";
cin >> b;  
swap (&a, &b); 
cout << a << " " << b; 
return 0; 
}
Because they are different types. Make temp a pointer if you want to use it like one.
Thanks!
Though you may want to note that you can make temp equal the contents of whatever b is pointing to; assign temp to whatever b is pointing to rather than the pointer itself.
Topic archived. No new replies allowed.