Purpose of Dummy Parameter in Postfix Operator Overload? c++

前端 未结 3 616
栀梦
栀梦 2021-01-06 03:28

When overloading the postfix operator, I can do something simple like

Class Foo
{
private: 
   int someBS;
public:
   //declaration of  pre &postfix++
           


        
3条回答
  •  难免孤独
    2021-01-06 03:44

    The dummy parameter is simply there to distinguish between the postfix and prefix operators. The name ++ or -- is the same in both cases, so there has to be some way to specify which one you're defining. Adding a dummy parameter is perhaps not elegant, but any alternatives would probably have required inventing new syntax (perhaps a postfix keyword, which would break code that uses postfix as an identifier).

提交回复
热议问题