Can operator [] accept two arguments?

P

PengYu.UT

I'm wondering whether the operator [] can accept more than 1 arguments

Suppose I have a object which is essentially a 2 dimensional array, I
want to use operator [] to access the data. I don't what to use [] to
return a 1 dimentional array and use another [] to access the data in
this 1 dimentional array.

Is it possible to accept 2 arguments?

Thanks,
Peng
 
G

Greg

I'm wondering whether the operator [] can accept more than 1 arguments

Suppose I have a object which is essentially a 2 dimensional array, I
want to use operator [] to access the data. I don't what to use [] to
return a 1 dimentional array and use another [] to access the data in
this 1 dimentional array.

Is it possible to accept 2 arguments?

Thanks,
Peng

No, an overloaded subscript operator accepts only one argument (which
for the overloaded operator can be of any type, not necessarily an
integral type).

It is possible to have the [] operator return a reference to the object
itself, or some other object that also implements the [] operator.
Doing so would allow multiple subscript operations to be chained:

MyObject[index1][index2];

Alternately, instead of overloading the [] operator, overload the ()
operator instead. The () operator can be declared to accept any number
of arguments. The only meaningful difference between between the
overloaded versions is the difference between having round or having
square brackets.

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top