Hi all
This seems to me a peculiar problem, but confounding nonetheless...
The problem seems to be that an overloaded subscript operator isn't being called unless it is called explicitly
I can't find anything on the Internet or any textbooks about this. Any clues as to why this doesn't work would be appreciated.
Thanks, Greg
This seems to me a peculiar problem, but confounding nonetheless...
The problem seems to be that an overloaded subscript operator isn't being called unless it is called explicitly
Code:
struct myStruct
{
myStruct& operator[] (int index)
{
return *(this + index);
}
bool val1;
int val2;
float val3;
double val4;
};
int main()
{
myStruct *s = new myStruct[5];
s[0].val1 = true;//works, but does not call the overloaded operator
s->operator[](0).val1 = 1;//calls the overloaded operator - also works
...
}
Thanks, Greg
Comment