Connecting Tech Pros Worldwide Forums | Help | Site Map

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

iceColdFire
Guest
 
Posts: n/a
#1: Jul 23 '05
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


John Carson
Guest
 
Posts: n/a
#2: Jul 23 '05

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


"iceColdFire" <icoldfire@yahoo.com> wrote in message
news:1117280780.942311.67050@o13g2000cwo.googlegro ups.com[color=blue]
> 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...[/color]

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.


--
John Carson

Closed Thread


Similar C / C++ bytes