overloading postfix and prefix operators

前端 未结 4 1753
既然无缘
既然无缘 2020-11-30 09:23

please consider following code

#include 
using namespace std;
class Digit
{

private:
    int m_digit;
public:
    Digit(int ndigit=0){
             


        
4条回答
  •  盖世英雄少女心
    2020-11-30 09:53

    The pre- and post-increment are two distinct operators, and require separate overloads.

    C++ doesn't allow overloading solely on return type, so having different return types as in your example wouldn't be sufficient to disambiguate the two methods.

    The dummy argument is the mechanism that the designer of C++ chose for the disambiguation.

提交回复
热议问题