C ++重载:重载[] []运算符 [英] C++ Overloading : Overloading the [][] operator

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

问题描述

问题是是否可能重载[] []。

The question is whether it is possible to overload [ ][ ] .

在正常情况下,如vector<载体, int>>,我们重载[]操作符。

Well in normal circumstances like vector< vector < int > > , we are overloading the [ ] opertor .

但是如果定义一个特殊含义[] []是可能有一个这样的操作符

But in cases where if define a special meaning to [ ][ ] is it possible to have such an operator

推荐答案

没有特殊的[] []运算符;

There is no special [][] operator; it's operator[] applied to the result of another operator [].

你可以通过让第一个操作符返回一个特殊的临时对象来赋予[] []构造的特殊含义。 ,它也有[]运算符。

You can give special meaning to [][] construct by having the first operator returning a special temporary object, which also has [] operator.

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

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