hi,
i need to ask a general question about the delete:
for example,if i have implemented a class name_class
class name_class{
....
...
};
once i call it in the main an object of class_name type
is it right to get rid of it in the following way?
int main(){
class_name obg1;
....
..
class_name *ptr=&obj1;
delete ptr;
return 0;
}
Since you did not create the object with new, (in this case, the object is 'obj1' -- which was created with local scope... not with new)... you must not delete it.
He's a pretty fast ninja if he beat you by a whole 15 minutes!
EDIT: @Zexd below: The question was already answered by Disch, who posted a full 24 minutes ago! There's no need to post an additional post to potentially cause confusion with conflicting information.
delete is used to de-allocate the memory that is allocated with new.
Here is an example:
1 2
int *pointer = newint; // int is here just to show you what it does. You'll use much bigger structs or arrays
delete pointer; // de-allocating the memory allocated with new
He's a pretty fast ninja if he beat you by a whole 15 minutes!
Well, I started writing my reply before Disch's got posted, and then got distracted by actual, y'know, work. Then I came back to it and finished it, forgetting to check whether someone else had answered in the meantime