Please do not mark as duplicate, while there are similar questions to mine, they were either answered using pointers, did not address the same issue that I have, or they pertained to the language C instead of C++.
I am trying to pass an array of structs to a function, but when I try to do so, I am getting an error: declaration of ‘a’ as array of references. I think the problem may lay in the fact the compiler is reading it as an array instead of as a struct, but I am not sure how to remedy this problem.
I have defined a struct of three elements:
struct StructA {
string name;
float income;
int amount;
}
Declared this struct within main:
StructA a[15];
And am passing it to a function like so:
void FunctionA(StructA& a[], int& count) { //& to pass by reference
}
Furthermore, right below the definition of StructA, I have the matching function prototype for the function above.
What am I doing wrong?
EDIT: Someone marked this question as a duplicate of another; it is not. I am in an intro to programming class, and as I clearly stated up top, I cannot use a pointer. Guess what the other question uses? A pointer. See the difference? Furthermore, on a more practical level, I already tried the solution recommended in Pass a dynamic array of objects to function and it did not work for me and since I cannot comment in the other question, I have to ask a new question. I will just wait until I can ask my professor, grazie.
std::vector<T>ofStructAand pass astd::vector<StructA>& containerto your function.