Why does pre-increment work but post-increment does not on a reference variable?
#include <iostream>
void swap(int&, int&);
int main()
{
int x=10, y=20;
int &a=x, &b=y;
swap(++a, ++b); //swap (a++,b++) is not allowed.
printf("%d %d ", a, b);
return 0;
}
void swap(int& x, int& y)
{
x+=2;
y+=3;
}
Why is swap(++a, ++b)
allowed but swap(a++, b++)
says:
[Error] invalid initialization of non-const reference of type 'int&' from an rvalue of type 'int'