Connecting Tech Pros Worldwide Help | Site Map

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

  #1  
Old July 23rd, 2005, 05:52 AM
iceColdFire
Guest
 
Posts: n/a
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

  #2  
Old July 23rd, 2005, 05:52 AM
John Carson
Guest
 
Posts: n/a

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 Threads
Thread Thread Starter Forum Replies Last Post
Problem with .txt file Filemaxor answers 0 March 9th, 2008 10:00 PM
Graphs/statistics using wxPython Jan Danielsson answers 8 July 19th, 2005 03:29 AM