Connecting Tech Pros Worldwide Help | Site Map

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

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 04:52 AM
iceColdFire
Guest
 
Posts: n/a
Default (15+n2); not working where n2 is class

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, 04:52 AM
John Carson
Guest
 
Posts: n/a
Default 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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.