Have a n00bish question, I'm overloading the [] operator to implement an array like class.
It works fine, my problem arises when I've a pointer to the object.
MyClass c;
c[5] works fine
However
MyClass *c = new MyClass();
*c[5] will not work since the precedence of [] is higher than that of *
So I've to write it as
(*c)[5] which is not looking good for me any solution to overcome this.
int main(){
MyArr m;
m[2] = 5; // <--- works fine
MyArr *k = new MyArr();
(*k)[2] = 3; // <--- I want to be able to just use *k[2] = 3 or k[2] = 3 instead !!!!
uint8_t y = (*k)[2];
std::cout << (int)y << std::endl;
return 0;
}