I was wondering how to pass a struct array by reference into a function. I found how to do it with pointers but wanted to learn with references too. Here is my code thus far.
struct employeeType
{
string firstName;
...
double monthlyBonus;
};
void readEmpData(ifstream& infile, employeeType *emp, int length);
I thought I just did employeeType& emp or employeeType& emp[] but get errors and everything I have googled just did pointers.
Here is the full code at pastebin for clarification for my learning experiment:
http://pastebin.com/6NfZ3LC4
I assume you want readEmpData to read in an array of employees from a file. In this case, the caller wouldn’t know how many employees there are and so the array and its length should be output parameters. An appropriate signature would be:
or
You could also define the operator
<<for employeeType and read using STL: