I am playing a bit around with arrays and passing pointers by reference to functions. Consider as an example the following code:
#include<iostream>
void test_fn(const int* const &i){
std::cout<<*i<<std::endl;
}
int main(){
int arr_1[5] {1, 3, 6, 4, 5};
int *int_ptr1 {nullptr};
int_ptr1=arr_1;
test_fn(int_ptr1);
return 0;
}
This code runs properly.
However, if I amend the definition of the test_fn to read:
void test_fn(const int* &i){
std::cout<<*i<<std::endl;
}
I get the following error:
cannot bind non-const lvalue reference of type 'const int*&' to an rvalue of type 'const int*'
My question is: Why is this an issue in the second example but not in the first, where the only difference is that the pointer is being passed as a const pointer?
std::array??