Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Can operator [] accept two arguments?

Reply
Thread Tools

Can operator [] accept two arguments?

 
 
PengYu.UT@gmail.com
Guest
Posts: n/a
 
      11-05-2005
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

 
Reply With Quote
 
 
 
 
Greg
Guest
Posts: n/a
 
      11-05-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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

 
Reply With Quote
 
 
 
 
Marcus Kwok
Guest
Posts: n/a
 
      11-06-2005
(E-Mail Removed) <(E-Mail Removed)> wrote:
> 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?


No, see
http://www.parashift.com/c++-faq-lit...html#faq-13.10

--
Marcus Kwok
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to compare two SOAP Envelope or two Document or two XML files GenxLogic Java 3 12-06-2006 08:41 PM
can operator << accept two parameters? TOMERDR C++ 5 04-04-2006 02:41 PM
operator new does not accept 3 arguments !? Gernot Frisch C++ 6 11-29-2005 01:44 PM
Can Compaq Presario 7599 accept a digital output video card ?? Guido Computer Support 2 12-10-2004 05:00 AM
2600 + 4BRI: can I accept V.120 ISDN calls from GSM network ? Help! Gio Cisco 1 02-23-2004 04:29 PM



Advertisments