473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Can operator [] accept two arguments?

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

Nov 5 '05 #1
2 5861
Pe*******@gmail.com 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

Nov 5 '05 #2
Pe*******@gmail.com <Pe*******@gmail.com> 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
Nov 6 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: glen stark | last post by:
Hi all. I'm working with an array of member function pointers (they are all get function of the class Bead). The typedef is: typedef _real (Bead::*_beadGfp)(void); I have a class System...
5
by: bsaucer | last post by:
I am creating a class with operator overloads. It makes references to another class I've created, but do not wish to modify. I try to overload an operator having arguments having the other class...
2
by: Dave | last post by:
Hello all, It is my understanding that there is not a portable way to write a user-defined manipulator that takes arguments. Please consider below which, for purposes of illustration,...
19
by: jacob navia | last post by:
C++ introduced an interesting feature (among others): operator overloading. The idea is to build a mechanism for the user defining its own number types and the operations to be done with them. ...
67
by: carlos | last post by:
Curious: Why wasnt a primitive exponentiation operator not added to C99? And, are there requests to do so in the next std revision? Justification for doing so: C and C++ are increasingly used...
2
by: Mr Dyl | last post by:
I'm having a few issues porting Windows code to Linux (VS.Net 2003 to GCC 4.0.1). So this probably has something to do with VS not catching non-compliant code. I'd like to simplify this problem,...
7
by: Jim Langston | last post by:
What I want to do is have an operator= accept a template variable. I will have some classes which all will contain an instance of a different class. I want an operator= in yet a 3rd class to...
5
by: Kith Kanan | last post by:
In a recent thread "Why is overloading operator. (member operator) forbidden", someone wrote a code like the following: template <typename R, typename... Argtypes> class gen_send { private:...
5
by: kyosohma | last post by:
I have created what amounts to a simple GUI email sending program using Python + wxPython. I have modified the mailto registration in the Windows Registry so that it launches the script when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.