Click here to Skip to main content
15,565,598 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I don't understand the meaning of this error message.
why do I get this error? here is the coding;

#include <iostream>
using namespace std;

int f(int &x, int c);

int main()
cout <<" testing reference"<<f(5,5);

return 0;

int f(int &x, int c) {
c = c - 1;
if (c == 0) return 1;
x = x + 1;
return f(x, c) * x;

1 solution

You are passing first argument as reference. It means that the actual argument should be an object that can be referenced, it can not be an immediate constant such as 5. Passing by reference allows the function modify the value of this argument, so it should be a variable.

You should either remove '&' from the function signature, or use a variable to pass as the first argument.

Share this answer
David A. Gray 29-Jun-15 12:53pm    
Equally important is that if the argument is a reference, you must pass by reference as well, using the address of operator (&).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900