Strange compilation error on reference passing argument to function

Posted by Grewdrewgoo Goobergabbsoen on Stack Overflow See other posts from Stack Overflow or by Grewdrewgoo Goobergabbsoen
Published on 2013-10-30T21:51:04Z Indexed on 2013/10/30 21:53 UTC
Read the original article Hit count: 152

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about c++

Related posts about reference