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

二次信任 提交于 2019-11-27 14:48:47
Daniel Earwicker

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.

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
};
RC.

Postfix has an int argument in the signature.

Class& operator++();    //Prefix 
Class  operator++(int); //Postfix 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!