overloading postfix and prefix operators

前端 未结 4 1746
既然无缘
既然无缘 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条回答
  •  萌比男神i
    2020-11-30 10:04

    The operator, just as any function, is identified by the signature. The return type and modifiers before the function/operator name is not included in this. Your operators names are here

    operator++()
    operator++(int)
    

    This is the only way the compiler distinguishes between the two. As for the Digit& and Digit return values; They are needed because of the way ++x, and x++ are supposed to operate.

提交回复
热议问题