How to differentiate (when overloading) between prefix and postfix forms of operator++? (C++)

前端 未结 4 1569
眼角桃花
眼角桃花 2020-12-03 16:05

Because I\'ve overloaded the operator++ for an iterator class

template
typename list::iterator& list::it         


        
相关标签:
4条回答
  • 2020-12-03 16:25

    Postfix has an int argument in the signature.

    Class& operator++();    //Prefix 
    Class  operator++(int); //Postfix 
    
    0 讨论(0)
  • 2020-12-03 16:29

    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
    };
    
    0 讨论(0)
  • 2020-12-03 16:29

    everything about operator overloading http://www.parashift.com/c++-faq-lite/operator-overloading.html

    0 讨论(0)
  • 2020-12-03 16:36

    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.

    0 讨论(0)
提交回复
热议问题