二元或一元运算符 [英] binary or unary operator

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

问题描述

嗨世界。我有个问题。运算符[]二元还是一元?请告诉我为什么它是一元的或为什么它是二元的?

谢谢

hi world. i have a question. is the operator [] binary or unary? and please tell me why it is unary or why it is binary?
thanks

推荐答案

它被称为订阅运营商 [ ^ ]这是二元运算符的一个特例,它需要左侧的可索引值和索引值。



但它实际上也不是:它是一种语法糖而是语言的一部分,而不是一个真正的操作员。

你可以超载它虽然: http://www.learncpp.com/cpp-tutorial/98- overloading-the-subscript-operator / [ ^ ]
It's called the Subscript operator[^] and it's a special case of a binary operator in that it requires an indexable value on teh left and a indexing value as well.

But it isn't really either: it's a "syntactic sugar" and part of the language instead of being a "real" operator.
You can overload it though: http://www.learncpp.com/cpp-tutorial/98-overloading-the-subscript-operator/[^]


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

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