I'm coding a program which calculates time values in hh:mm:ss format.
I'm reading times from a file containing 1 time string per line. After reading times, i continue reading operations on the time in the same file. operations are like this:
167+234
which basically means i take the 167th row in the file and add it with 234th.
here is what i have so far. Note the >> operator is also overloaded.
And this is my overloaded + operator
When i try to compile i get this error:
Any ideas?
I'm reading times from a file containing 1 time string per line. After reading times, i continue reading operations on the time in the same file. operations are like this:
167+234
which basically means i take the 167th row in the file and add it with 234th.
here is what i have so far. Note the >> operator is also overloaded.
Code:
myClass operationAnswer, myArray[300]; // this is actually a dynamic array in my program.
int Index1, Index2;
char sign;
// Assume i already read the times... Reading operations now
while(!fin.eof() && fin >> Index1
>> sign
>> Index2) {
if (sign == '+')
myAnswer = myArray[Index1] + myArray[Index2];
else
// do subtraction
Code:
DateProcessorClass operator + (DateProcessorClass& left, DateProcessorClass& right)
{
/* Cannot pass by reference because we'll expose private variables */
int resultSec, resultMin, resultHour;
int tempMinutes, tempHours;
resultSec = left.getSeconds() + right.getSeconds();
tempMinutes = left.getMinutes();
if (resultSec > 60)
{
resultSec = resultSec - 60;
tempMinutes = left.getMinutes() + 1;
}
resultMin = tempMinutes + right.getMinutes();
tempHours = left.getHours();
if (resultMin > 60)
{
resultMin = resultMin - 60;
tempHours = left.getHours() + 1;
}
resultHour = tempHours + right.getHours();
return DateProcessorClass(resultHour,resultMin,resultSec);
}
Code:
main.obj : error LNK2019: unresolved external symbol "class DateProcessorClass __cdecl operator+(class DateProcessorClass const &,class DateProcessorClass const &)" (??H@YA?AVDateProcessorClass@@ABV0@0@Z) referenced in function _main Debug/DateProcessorClass.exe : fatal error LNK1120: 1 unresolved externals
Comment