Please tell me why fun(k++)
is wrong while fun(++k)
is okay in the following code. The error information is error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
#include <iostream>
using std::cout;
void fun(int &k)
{
cout << k;
}
int main()
{
int k = 1;
fun(k++); // error
fun(++k); // good
return 0;
}