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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
/***********************************************************************
This function modifies an employee's info
***********************************************************************/
void EmployeeList::modEmp(int i)
{
int mod = 0;
double mod1 = 0;
char name[30];
char choice;
cout << "Would you like to modify the employee's first name?" << endl;
cin >> choice;
if (choice == 'Y' || choice == 'y')
{
cout << "Please enter the new employee's first name." << endl;
cin >> name;
workers[i].setFName(name);
}
cout << "Would you like to modify the employee's last name?" << endl;
cin >> choice;
if (choice == 'Y' || choice == 'y')
{
cout << "Please enter the new employee's last name." << endl;
cin >> name;
workers[i].setLName(name);
}
cout << "Would you like to modify the employee's pay rate?" << endl;
cin >> choice;
if (choice == 'Y' || choice == 'y')
{
cout << "Please enter the new employee's pay rate." << endl;
cin >> mod1;
workers[i].setRate(mod1);
workers[i].setWage(workers[i].getRate(), workers[i].getHours());
}
cout << "Would you like to modify the employee's hours?" << endl;
cin >> choice;
if (choice == 'Y' || choice == 'y')
{
cout << "Please enter the new employee's hours." << endl;
cin >> mod;
workers[i].setHours(mod);
workers[i].setWage(workers[i].getRate(), workers[i].getHours());
}
writeEmp();
}
/***********************************************************************
This function returns how many employees there currently are
***********************************************************************/
int EmployeeList::numEmp()
{
return count;
}
/***********************************************************************
This function returns a single employee
***********************************************************************/
Employee EmployeeList::retEmp(int i)
{
return workers[i];
}
/************************************************************************
These next two functions define the << and >> operators for EmployeeList
************************************************************************/
ostream &operator << (ostream &strm, EmployeeList &obj)
{
for (int i = 0; i < count; i++) //Line 287
{
strm << workers[i]; //Line 289
}
return strm;
}
istream &operator >> (istream &strm, EmployeeList &obj)
{ //Line 296
workers[count] = obj; //Line 297
return strm;
}
/******************************************************************
This function writes workers to output file
******************************************************************/
void EmployeeList::writeEmp()
{
ostream outFile; //Line 307
outFile.open("EmployeeDataBase.dat"); //Line 308
for (int i = 0; i < count; i++)
{
outFile >> workers[i]; //Line 312
}
outFile.close(); //Line 315
}
|
Compilation errors:
csci2>g++ -c EmployeeList.cpp
EmployeeList.cpp: In member function `Employee* EmployeeList::employeeHolder(std::string)':
EmployeeList.cpp:22: error: no matching function for call to `std::basic_ifstream<char, std::char_traits<char> >::open(std::string&)'
/usr/sfw/lib/gcc/i386-pc-solaris2.10/3.4.3/../../../../include/c++/3.4.3/fstream:570: note: candidates are: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
EmployeeList.cpp: In function `std::ostream& operator<<(std::ostream&, EmployeeList&)':
EmployeeList.cpp:287: error: invalid operands of types `int' and `<unknown type>' to binary `operator<'
EmployeeList.cpp:289: error: `workers' undeclared (first use this function)
EmployeeList.cpp:289: error: (Each undeclared identifier is reported only once for each function it appears in.)
EmployeeList.cpp: In function `std::istream& operator>>(std::istream&, EmployeeList&)':
EmployeeList.cpp:297: error: `workers' undeclared (first use this function)
EmployeeList.cpp: In member function `void EmployeeList::writeEmp()':
/usr/sfw/lib/gcc/i386-pc-solaris2.10/3.4.3/../../../../include/c++/3.4.3/ostream:361: error: `std::basic_ostream<_CharT, _Traits>::basic_ostream() [with _CharT = char, _Traits = std::char_traits<char>]' is protected
EmployeeList.cpp:307: error: within this context
EmployeeList.cpp:308: error: 'struct std::ostream' has no member named 'open'
EmployeeList.cpp:312: error: no match for 'operator>>' in 'outFile >> ((EmployeeList*)this)->EmployeeList::workers[i]'
Employee.h:88: note: candidates are: std::istream& operator>>(std::istream&, Employee&)
EmployeeList.h:42: note: std::istream& operator>>(std::ostream&, EmployeeList&)
EmployeeList.cpp:296: note: std::istream& operator>>(std::istream&, EmployeeList&)
EmployeeList.cpp:315: error: 'struct std::ostream' has no member named 'close'
Now what I am confused about each error is as follows:
Line 22: I have seen that error before, bt only with user defined functions (not ifstream declerations)
The rest: a combination of not being declared (even though it is declared in EmployeeList.h) and for some reason other little things (like seeming not to be including the fstream library even though it is included on top).
Any help is, as always, much appreciated. :)
EDIT: Labeled all lines which have errors in the second part (I think) since I couldn't fit it all in one post.