I was playing with classes and i met with something very interesting
I wrote something like that
void tester()
{
NameOfClass *new_guy = new NameOfClass [5];
new_guy -> setSomeKindOfValue(500);
cout << new_guy ->getSomeKindOfValue() << endl;
new_guy++;
new_guy ->setSomeKindOfValue(400);
cout << new_guy -> getSomeKindOfValue() << endl;
//new_guy --; if i do not comment this place, destructor will be invoked forever...
delete [] new_guy ;
}
so i thought about something like that:
void tester()
{
int rozmiar = 0;
char * k= new char[5];
k[0] = 'a';
k[1] = 'b';
k[2] = 'c';
k[3] = 'd';
k[4] = '\0';
while(*k++)
rozmiar++;
delete []k; //so will it free reserved memory or not?
}
Of course programs are written just to show you what i meant...
So how do you think? If i want to free memory, should the pointer point to the beggining of the dynamic table?
Best regards :)


Sign In
Create Account

Back to top









