views:

1371

answers:

3

Becuase I've overloaded the operator++ for an iterator class

template typename list::iterator& list::iterator::operator++() { //stuff }

But when I try to do

list::iterator IT; IT++;

I get a warning about there being no postifx ++, using prefix form. How can I specifically overload the prefix/postifx forms?

+6  A: 

Write a version of the same operator overload, but give it a parameter of type int. You don't have to do anything with that parameter's value.

If you're interested in some history of how this syntax was arrived out, there's a snippet of it here.

Daniel Earwicker
+12  A: 

http://www.devx.com/tips/Tip/12515

class Date {
 //...
 public:
 Date& operator++(); //prefix
 Date& operator--(); //prefix
 Date operator++(int unused); //postfix
 Date operator--(int unused); //postfix
};
zaratustra
Postfix operators should return by value, not reference. I guess there might be very strange situations where they can return a reference, but what to? Not this, because it has been incremented...
Steve Jessop
+5  A: 

Postfix has an int argument in the signature.

Class& operator++();    //Prefix 
Class  operator++(int); //Postfix
RC