I have some doubts about class accessors. In a nutshell, assume you have a class like this:
class CTest{
public:
CTest() {
mlist = new int*[10];
for(int i=0;i<10;i++){
mlist = new int(i);
}
curr_elem = mlist[4];
}
int *GetCurr() { return curr_elem; }
private:
int **mlist;
int *curr_elem;
};
So we have an array of 10 int pointers with values from 0 to 9, and another int pointer to the element at location 4. Cool.
Now if I do something like this:
CTest p;
int* point = p.GetCurr();
delete point;
both curr_elem and mlist[4] point to nothing (err... actually they point to a unknow memory location, but it is the same :D )
Is there a way to make impossible the "delete point" call? Or at least, to do not corrupt the private members of CTest ?