Why doesn't this code work
class myclass {
public:
int *ptrarray;
myclass() {
ptrarray = new int[2];
*ptrarray[0] = 5; //here I want to set the value of ptrarray[0] to 5, not its adress
*ptrarray[1] = 10;//here I want to set the value of ptrarray[1] to 10, not its adress
}
};
int main() {
myclass a;
a->ptrarray[1] = 15; //now I want to change the value of ptrarray[1]
}
It seems this is supposed to be the way to reference a member pointer of a class, but I guess it is not? How would I fix this code so it will work?