I have a basic question about array and pointer in C / C ++.
Say I have:
Foo* fooPtrArray[4];
How to pass fooPtrArrayto a function? I tried:
int getResult(Foo** fooPtrArray){}
int getResult(Foo* fooPtrArray[]){}
How can I handle an array of pointers?
EDIT: I once thought the error message was related to passing the wrong array of pointers, but from all the answers, I understand that this is something else ... (pointer assignment)
Error msg:
Description Resource Path Location Type incompatible types in assignment of
`Foo**' to `Foo*[4]' tryPointers.cpp tryPointers line 21 C/C++ Problem
I don’t quite understand why he says: Foo * * to Foo * [4]. If as a function parameter they mutually change with each other, why does this give me a compilation error during assignment?
I tried to duplicate the error message with minimal code as follows:
#include <iostream>
using namespace std;
struct Foo
{
int id;
};
void getResult(Foo** fooPtrArray)
{
cout << "I am in getResult" << endl;
Foo* fooPtrArray1[4];
fooPtrArray1 = fooPtrArray;
}
int main()
{
Foo* fooPtrArray[4];
getResult(fooPtrArray);
}