Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Overloading : Overloading the [][] operator [duplicate]

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

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

like image 703
Anil Shanbhag Avatar asked Aug 16 '11 09:08

Anil Shanbhag


2 Answers

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.

like image 133
hamstergene Avatar answered Oct 06 '22 02:10

hamstergene


No, you will have to overload [] to return a value which itself has [] overloaded.

like image 37
Puppy Avatar answered Oct 06 '22 02:10

Puppy