Hi All,
This may be very obvious question, pardon me if so.
I have below code snippet out of my project,
#include <stdio.h>
class X
{
public:
int i;
X() : i(0) {};
};
int main(int argc,char *arv[])
{
X *ptr = new X[10];
unsigned index = 5;
cout<<ptr[index].i<<endl;
return 0;
}
Question
Can I change the meaning of the ptr[index]
? Because I need to return the value of ptr[a[index]]
where a is an array for subindexing. I do not want to modify existing source code. Any new function added which can change the behavior is needed.
Since the access to index operator is in too many places (536 to be precise) in my code, and has complex formulas inside the index subscript operator, I am not inclined to change the code in many locations.
PS :
1. I tried operator overload and came to conclusion that it is not possible.
2. Also p[i] will be transformed into *(p+i). I cannot redefine the basic operator '+'.
So just want to reconfirm my understanding and if there are any possible short-cuts to achieve.
Else I need fix it by royal method of changing every line of code :) .