473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

problem overloading + operator

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.

Expand|Select|Wrap|Line Numbers
  1. myClass operationAnswer, myArray[300]; // this is actually a dynamic array in my program.
  2. int Index1, Index2;
  3. char sign;
  4.                 // Assume i already read the times... Reading operations now
  5.         while(!fin.eof() && fin >> Index1
  6.                                 >> sign
  7.                                 >> Index2) {
  8.  if (sign == '+') 
  9.    myAnswer = myArray[Index1] + myArray[Index2];
  10.  else
  11.   // do subtraction  
  12.  
And this is my overloaded + operator
Expand|Select|Wrap|Line Numbers
  1. DateProcessorClass operator + (DateProcessorClass& left, DateProcessorClass& right)
  2. {
  3.     /* Cannot pass by reference because we'll expose private variables */
  4.     int resultSec, resultMin, resultHour;
  5.     int tempMinutes, tempHours;
  6.  
  7.     resultSec = left.getSeconds() + right.getSeconds();
  8.     tempMinutes = left.getMinutes();
  9.     if (resultSec > 60)
  10.     {
  11.         resultSec = resultSec - 60;
  12.         tempMinutes = left.getMinutes() + 1;
  13.     }
  14.     resultMin = tempMinutes + right.getMinutes();
  15.     tempHours = left.getHours();
  16.     if (resultMin > 60)
  17.     {
  18.         resultMin = resultMin - 60;
  19.         tempHours = left.getHours() + 1;
  20.     }
  21.     resultHour = tempHours + right.getHours();
  22.     return DateProcessorClass(resultHour,resultMin,resultSec);
  23. }
  24.  
When i try to compile i get this error:

Expand|Select|Wrap|Line Numbers
  1. 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
  2. Debug/DateProcessorClass.exe : fatal error LNK1120: 1 unresolved externals
  3.  
Any ideas?
Oct 11 '06 #1
1 1357
errr... problem solved.
I was passing parameters as constants in my + operator function in the declaration of the function in the header file.

DateProcessorClass operator + (const DateProcessorClass& left, const DateProcessorClass& right);

Duh...
Oct 11 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: | last post by:
Hi all, I've been using C++ for quite a while now and I've come to the point where I need to overload new and delete inorder to track memory and probably some profiling stuff too. I know that...
34
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment...
16
by: gorda | last post by:
Hello, I am playing around with operator overloading and inheritence, specifically overloading the + operator in the base class and its derived class. The structure is simple: the base class...
2
by: pmatos | last post by:
Hi all, I'm overloading operator<< for a lot of classes. The question is about style. I define in each class header the prototype of the overloading as a friend. Now, where should I define the...
5
by: luca regini | last post by:
I have this code class M { ..... T operator()( size_t x, size_t y ) const { ... Operator overloading A ....} T& operator()( size_t x, size_t y )
5
by: Jerry Fleming | last post by:
As I am newbie to C++, I am confused by the overloading issues. Everyone says that the four operators can only be overloaded with class member functions instead of global (friend) functions: (), ,...
14
by: Frank | last post by:
Hello everyone, I am having trouble overloading the < operator for an assignment. I use a struct that contains information and I would like to sort this structure using STL sort with my own...
9
by: sturlamolden | last post by:
Python allows the binding behaviour to be defined for descriptors, using the __set__ and __get__ methods. I think it would be a major advantage if this could be generalized to any object, by...
2
by: Colonel | last post by:
It seems that the problems have something to do with the overloading of istream operator ">>", but I just can't find the exact problem. // the declaration friend std::istream &...
8
by: Wayne Shu | last post by:
Hi everyone, I am reading B.S. 's TC++PL (special edition). When I read chapter 11 Operator Overloading, I have two questions. 1. In subsection 11.2.2 paragraph 1, B.S. wrote "In particular,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.