solving error in code

Hi,
I'm a beginner in c++ programming and am unable to figure out what the following error message means and how to solve it. I'm posting both the code as well as the errors. Kindly help.

thanks in advance,
upad

Error message:
error LNK2019: unresolved external symbol "float __cdecl processEmp1(class std::basic_ifstream<char,struct std::char_traits<char> > &,class std::basic_ofstream<char,struct std::char_traits<char> > &)" (?processEmp1@@YAMAAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@AAV?$basic_ofstream@DU?$char_traits@D@std@@@2@@Z) referenced in function _main
1>C:\Users\Owner\Documents\Visual Studio 2010\Projects\Ch8\Debug\Ch8.exe : fatal error LNK1120: 1 unresolved externals

Code:
# include <iostream>
# include <cmath>
# include <fstream>
# include <cstdlib>
# include <string>

using namespace std;
#define inFile "EmpFile.txt" // employee file
#define outFile "Salary.txt" // payroll file

//functions used
float processEmp1(ifstream& , ofstream&);

int main()
{
ifstream ens;
ofstream puts;
float totalPayroll;


ens.open(inFile);
if (ens.fail())
{
cerr << "*** ERROR: Cannot open " << inFile << " for input." << endl;
return EXIT_FAILURE;

}

puts.open(outFile);
if (puts.fail())
{
cerr << "*** ERROR: Cannot open " << outFile << " for output." << endl;
//ins.close();
return EXIT_FAILURE;

}

//process all employees
totalPayroll = processEmp1 (ens,puts);

//display result
cout << "Total payroll is $" << totalPayroll << endl;

//close files
ens.close();
puts.close();

system ("pause");
return 0;

}

float processEmp1 (ifstream& ens, ofstream puts)
{
string firstName;
string lastName;
float hours;
float rate;
float salary;
float payroll=0.0;

//read first employee data record
ens >> firstName >> lastName >> hours >> rate;

while (!ens.eof())
{
salary = hours * rate;
puts << firstName << lastName << " " << salary << endl;

payroll += salary;

//read next employee's data record
ens >> firstName >> lastName >> hours >> rate;
}// end while

return payroll;
}
Last edited on
[code] tags plz, kthnx.

Also, notice that your processEmp1 function is defined differently than I expect you intended to define it (like its declaration further up). As a result, that function that you're using in main() has never been defined, and the linker hates it.

-Albatross
thanks Albatross,
but isn't function prototype defined that way??

You put an & symbol in the prototype and left it out in the definition.

Also, no need to post this in two forums... I thought that I was going crazy when I read the same post again and my reply wasn't there 0_o
Last edited on
Topic archived. No new replies allowed.