I am attempting to write the code for a console application that uses a static library in another project. In this code I am getting many errors pertaining to incomplete types and type names not allowed. I'd greatly appreciate it if someone would be able to help me with this. Thank you!
Errors in lines:
ifstream infile;
infile.open("pay.txt");
e[i] = new employee[i];
and any line that uses the dynamic array for class employee
To use an ifstream, you must also include the header <fstream>
employee *e[4]; This is an array of pointers. Did you mean to make an array of pointers, or did you mean to make an array of employee?
e[i] = new employee[i];
Wait, I see. So e[0] is a pointer to an array of 0 employees, and e[1] is a pointer to an array of 1 employees, and e[02] is a pointer to an array of 2 employees ... and e[n] is a pointer to an array of n employees. That really doesn't sound right.
infile >> firstname >> hoursworked >> overtimehourlyrate >> e[i];
So you're reading in a bunch of values... to pointers, so that makes no sense at all, and then you read in a value to... the pointer e[i], so that also makes no sense...
It looks to me like you don't understand pointers. You need to stop, and go back and learn about pointers, and arrays.
And then don't use them. This is C++; use a vector instead of an array.
I edited the code some, now my only error is "no operator matches these operands >>" when i try to populate the array. I must use pointers and arrays for this exercise.
em[i] = new employee[i];
Don't do this. This shouldn't even compile anymore. Are you a Java coder? You've got an obsession with creating objects on the heap.
infile >> em[i];
Did the employee type define the operator >> for use with it? I expect not.
So read in each value you want to some temporary variable, and then use that set the relevant variable inside the employee object.
I see that your program structure is to read 4 employees from file, and populate an array of 4 employee with that data, and then you never ever use that information again. That doesn't make a lot of sense.