Strange compilation error on reference passing argument to function
- by Grewdrewgoo Goobergabbsoen
Here's the code:
#include <iostream>
using namespace std;
void mysize(int &size, int size2);
int main()
{
int *p;
int val;
p = &val;
cout << p;
mysize(&val, 20); // Error is pointed here!
}
void mysize(int &size, int size2)
{
cout << sizeof(size);
size2 = size2 + 6000;
cout << size2;
}
Here's the error output from GCC:
In function 'int main()':
Line 10: error: invalid initialization of non-const reference of type 'int&' from a temporary of type 'int*'
compilation terminated due to -Wfatal-errors.
What does that imply? I do not understand the error message ... invalid initialization of a non-constant? I declared the prototype function above with two parameters to take, one a reference of an integer and one just an integer value itself. I passed the reference of the int (see line 10), yet this error keeps being thrown at me.
What is the issue?