Not sure why I’m getting this error. I have the following:
int* arr = new int[25];
int* foo(){
int* i;
cout << "Enter an integer:";
cin >> *i;
return i;
}
void test(int** myInt){
*myInt = foo();
}
This call here is where I get the error:
test(arr[0]); //here i get invalid conversion from int to int**
The way you’ve written it,
testtakes a pointer to a pointer to anint, butarr[0]is just anint.However, in
fooyou are prompting for anint, but reading into a location that is the value of an uninitialized pointer. I’d have thought you wantfooto read and return andint.E.g.
In this case it would make sense for test to take a pointer to an int (i.e.
void test(int* myInt)).Then you could pass it a pointer to one of the
intthat you dynamically allocate.