Thanks CornedBee,
Do you mean in the sample code,
Code:
myclasses[a][b] = something;
operator[] is invoked by the a-th instance of the array, and b and something are two input parameters for operator[] for the a-th element of the instance array?
Originally Posted by
CornedBee
Yes. The first [] applies to the array, the second to the instance.
Hi jian2587,
Originally Posted by
jian2587
for example you're creating a string class. you probably want [] to access the individual characters in your string. the compiler doesn't know how to do that, because there can be many different implementations of a string.
I do not know what you mean above. Could you show some pseude code please?
BTW: operator[] on string works good. Here is my test code, I do not know why you say it can not work.
Code:
#include <string>
using namespace std;
int main()
{
string str ("abcdefg");
char ch = str[3]; // ch is 'd'
return 0;
}
regards,
George