C ++增量运算符 [英] C++ increment operator

查看:103
本文介绍了C ++增量运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何区分重载operator ++的两个版本?

How to differentiate between overloading the 2 versions of operator ++ ?

const T& operator ++(const T& rhs)

哪一个?

i++;
++i;


推荐答案

这些运算符是一元的,一个右手参数。

These operators are unary, i.e., they do not take a right hand side parameter.

对于你的问题,如果你真的必须重载这些运算符,对于preincrement使用签名 const T& operator ++(),对于后增量, const T& operator(int)。 int参数是一个虚拟。

As for your question, if you really must overload these operators, for the preincrement use the signature const T& operator ++(), and for the postincrement, const T& operator(int). The int parameter is a dummy.

这篇关于C ++增量运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆