Problems Using Static Library

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <string>

using namespace std;
#include "Employee.h"
using namespace employeepay;

int main()
{		int choice;
	do {
		string filename;
		string* firstname;
		double* hoursworked;
		double* overtimehourlyrate;
		employee *e[4];							//dynamic instance of employee 5/14
		double h = 0, p = 0;

		ifstream infile;
		infile.open("pay.txt");

		for (int i = 0; i < n; ++i)
		{
			e[i] = new employee[i];														//dynamic array of employee 5/14
			infile >> firstname >> hoursworked >> overtimehourlyrate >> e[i];			//input info to array 5/14
		}


		cout << "Employee Program" << endl << "1. Read employee info from file" << endl << "2. Write employee info to a file" << endl
			<< "3. Show employee info on screen" << endl << "4. Show employee gross pay" << endl << "5. Exit" << endl;

		cin >> choice;

		if (choice == 1)
		{
			e.read(filename);
		}

		if (choice == 2)
		{
			e.read(filename);
			e.write(filename);
		}

		if (choice == 3)
		{
			e.read(filename);
			e.show();
		}

		if (choice == 4)
		{
			e.read(filename);
			e.grosspay(h, p);
			e.show();
		}

		if (choice == 5)
		{
			exit;
		}

		for (int i = 0; i < n; ++i)
		{
			delete[] employee[i];						//cleans up dynamically allocated memory 5/14
		}
		delete[] employee;
	} while (choice != 5);								//loops until user choice to end program 5/14
	return 0;
	system("pause");
}

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.


Last edited on
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <string>
#include <fstream>

using namespace std;
#include "Employee.h"
using namespace employeepay;

int main()
{		int choice;
	do {
		string filename;
		string* firstname;
		double* hoursworked;
		double* overtimehourlyrate;
		employee e;
		employee* em[4];							//dynamic instance of employee 5/14
		double h = 0, p = 0;

		ifstream infile;
		infile.open("pay.txt");

		for (int i = 0; i < 4; ++i)
		{
			em[i] = new employee[i];			//dynamic array of employee 5/14
			infile >> em[i];					//populates array with data from input file
		}


		cout << "Employee Program" << endl << "1. Read employee info from file" << endl << "2. Write employee info to a file" << endl
			<< "3. Show employee info on screen" << endl << "4. Show employee gross pay" << endl << "5. Exit" << endl;

		cin >> choice;

		if (choice == 1)
		{
			e.read(filename);
		}

		if (choice == 2)
		{
			e.read(filename);
			e.write(filename);
		}

		if (choice == 3)
		{
			e.read(filename);
			e.show();
		}

		if (choice == 4)
		{
			e.read(filename);
			e.grosspay(h, p);
			e.show();
		}

		if (choice == 5)
		{
			exit;
		}
		
		delete[] em[0];						//cleans up dynamically allocated memory 5/14
		delete[] em[1];
		delete[] em[2];
		delete[] em[3];
		delete[] em[4];

	} while (choice != 5);								//loops until user choice to end program 5/14
	return 0;
	system("pause");
}

Last edited on

employee* em[4];
Here you create an array of 4 pointers. Is that meant to be an array of pointers, or is it meant to be an array of 4 employee ?


now my only error is "no operator matches these operands >>"
No, it's still heaving with errors, mostly the same ones I identified before.
Last edited on
It is supposed to be an array of employee
Here is how to create an array of 4 employee.

employee em[4];
Ok, I edited that line. Now I am getting errors "no operator mathces these operands >>/=" in lines

1
2
3
			em[i] = new employee[i];		
			infile >> em[i];


how should I go about populating the array?
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.
Is this looking any better?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <string>
#include <fstream>

using namespace std;
#include "Employee.h"
using namespace employeepay;

int main()
{		int choice;
	do {
		string filename;
		string fname;
		string lname;
		double hworked;
		double rhourlyrate;
		double ohourlyrate;
		employee e;
		employee em[4];							//dynamic instance of employee 5/14
		double h = 0, p = 0;

		ifstream infile;
		infile.open("pay.txt");

		for (int i = 0; i < 4; ++i)
		{
			infile >> fname >> lname >> hworked >> rhourlyrate >> ohourlyrate;		//reads in data from input file
			em[i].setname(fname, lname);											//populates array with data from input file
			em[i].sethours(hworked);
			em[i].setregrate(rhourlyrate);
			em[i].setotrate(ohourlyrate);
                        em[i].show();
		}


		cout << "Employee Program" << endl << "1. Read employee info from file" << endl << "2. Write employee info to a file" << endl
			<< "3. Show employee info on screen" << endl << "4. Show employee gross pay" << endl << "5. Exit" << endl;

		cin >> choice;

		if (choice == 1)
		{
			e.read(filename);
		}

		if (choice == 2)
		{
			e.read(filename);
			e.write(filename);
		}

		if (choice == 3)
		{
			e.read(filename);
			e.show();
		}

		if (choice == 4)
		{
			e.read(filename);
			e.grosspay(h, p);
			e.show();
		}

		if (choice == 5)
		{
			exit;
		}

	} while (choice != 5);								//loops until user choice to end program 5/14
	return 0;
	system("pause");
}
Last edited on
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.
Yes, i forgot to add the show function in the for loop to print the data in the array. I will add that right now.
Topic archived. No new replies allowed.