Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No conversion from long unsigned int to long unsigned int&

Tags:

c++

g++

I receive the error message No known conversion for argument 2 from long unsigned int to long unsigned int& when I try to compile the following code:

void build(int* &array, unsigned long& index) {
  if (index == 0)
    return;
  else {
    heapify(array, index);
    build(array, index-1);
  }
}

Can someone explain why this happens, and what the logic is behind this error?

like image 339
ihm Avatar asked Dec 27 '22 21:12

ihm


1 Answers

The second argument of build requires a reference (marked with &). A reference is kind of like a pointer, so you can only use an actual variable that has a memory address.

This is why you can't use an expression like index-1.

like image 143
Gustav Larsson Avatar answered Feb 07 '23 20:02

Gustav Larsson