(15+n2); not working where n2 is class

I

iceColdFire

Hi,


I created a simple c++ program to overload operators,
class Number {...}


now when I use the class like,,,
Number n1(15);
Number n2(5);
(n1+n2).num;
(n1+10).num;
(15+n2);


I get error as 'Reverse iterator' in line (15+n2)...


Kindly explain what the issue is and what is reverse iterator...


Thanksin advance..
a.a.cpp
 
J

John Carson

iceColdFire said:
Hi,


I created a simple c++ program to overload operators,
class Number {...}


now when I use the class like,,,
Number n1(15);
Number n2(5);
(n1+n2).num;
(n1+10).num;
(15+n2);


I get error as 'Reverse iterator' in line (15+n2)...


Kindly explain what the issue is and what is reverse iterator...

You should supply the code, but my guess is that you have made operator+() a
member function, which means you can only use it when a Number object is on
the left hand side of the + sign. If you want a number object on the right
hand side, you need to make operator+() a non-member (and a friend if any
access to private members is required). You need to overload this operator
for the

(Number, int)
(int, Number)
and
(Number, Number)

combinations.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top