Variable Declaration Error

Hi
Can somebody please explain to me the following error and how to fix it


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void processMarks (string studentP, int & assgnmntP, int & markP,
bool doneP)
{
;
}

 int main()
 {

string student;
int mark;
int assignment;
bool done = false;
processMarks("Sally Williams", 1, mark, done);
 }



error: invalid initialization of non-const reference of type 'int&' from a temporary of type 'int'|
error: in passing argument 2 of 'void processMarks(std::string, int&, int&, bool)'|

Thanks
Your second parameter is an int& type.
1
2
3
4
void processMarks(string sudentP, int& assignmentP, int& markP, bool doneP)
{
  //...
}


This means that an object exists outside of this function and we can manipulate it.
However, in our main we call it with:
processMarks("Sally Williams", 1, mark, done);

When we type the integer 1, we are not creating an object. It has no address and so we also cannot manipulate it.

It would be like:
1
2
int a;
1 = a;


Sorry, should have giving a solution:

Solution 1:
1
2
void processMarks (string studentP, const int & assgnmntP, int & markP,
bool doneP);


Solution 2:
1
2
void processMarks (string studentP, int assgnmntP, int & markP,
bool doneP)
Topic archived. No new replies allowed.