answersLogoWhite

0

You use delete to release the memory occupied by an object that is being pointed to by the pointer you delete. Provided all base classes have a virtual destructor, it doesn't matter what the type of pointer you actually delete is, so long as it is a type of class from which the object is actually derived. The destructor from the most-inherited class (the object itself) will be called first, which calls the destructors of its immediate base classes, and theirs, and so on until the object is completely released from memory.

Note that you must not delete pointers to object references -- they must be nullified (not deleted) when they are no longer required. The referenced object will be deleted automatically when it falls from scope.

User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

Which function removes last element in a list?

If you are using the doubly-linked list from the STL library, then the function call:name_of_list.push_back();should delete the last element.


Why is parameter passing useful to programmers?

Because all software is written using functions and classes. If you do not know how to pass data from class to class, to function you are not a programmer.


How do you delete a node with two children in binary tree using c?

Use a recursive function. void delete_node (node* n) { /* ensure the given pointer is valid */ if (n==NULL) return; /* recursively delete the left child */ delete_node (n->left); n->left = NULL; /* recursively delete the right child */ delete_node (n->right); n->right = NULL; /* delete the data (assuming the data is a pointer)*/ free (n->data); n->data = NULL; /* finally, delete the node itself */ free (n); n=NULL; }


How do you swap classes and objects without using a template function?

You cannot swap classes, you can only swap objects. An object is an instance of a class while a class is a type definition; you cannot swap type definitions. It is not possible to write your own version of the swap algorithm without using templates. You can certainly write a function to cater for a specific type of object, but then you'd need to overload it in order to cater for all possible object types, which is clearly impossible since you have no knowledge of my objects let alone anyone else's.


Write a program to return a function using class in C Plus Plus?

Classes cannot return values, only functions can return values. But you cannot return a function from a function, you can only return a function pointer -- a pointer variable holding the address of the function you wish to return. All possible return values must be of the same type, therefore all function signatures and return types must be exactly the same -- only the name of the functions can differ.

Related Questions

Wapt delete aparticular character from astring using pointerand function?

yawa ang mobasa ani!!


Which function removes last element in a list?

If you are using the doubly-linked list from the STL library, then the function call:name_of_list.push_back();should delete the last element.


How do you delete data from a MySQL database using PHP?

To delete data from your MySQL database you need to use the mysql_query() function. Please see the example below: <?php mysql_query("DELETE FROM table_name WHERE field_name = 44"); ?>


How do you delete a file using keyboard?

how to delete a file using keyboard


How do you delete duplicate records in a MySQL database using PHP?

MySQL has three methods for removing duplicate records. Using Delete Join, remove duplicate records. In MySQL, we may utilise the DELETE JOIN query to swiftly eliminate duplicate records Using the ROW NUMBER() function, delete duplicate records. USE THE INTERMEDIATE TABLE TO DELETE DUPLICATE ROWS. To learn more about data science please visit- Learnbay.co


How do you delete weeworld?

You can not delete your weeworld you just stop using it!


How can you delete your facebook account using Gmail account?

No, you can't delete Facebook using Gmail. To delete Facebook, you have to go on their website. Gmail just is an interface.


What is used to add or delete programs on a computer?

Assuming you are using a computer with Windows operational system you can use the function "Add or Remove programs" function usually found in the control panel. You can directly access this function using the shortcut control.exe appwiz.cplwhich you can copy and paste into the run command bar (press windows button + run).


You had a friend using a screenname of mine on myspace how can you delete it?

ask tom to delete it.


How do you delete your Dragoart account?

using the delete options given or follow the steps provided to delete your dragoart account


Is inheritence in java only based on super class and sub class?

Yes. Inheritance is achieved by using the super class and sub class concept


Why is parameter passing useful to programmers?

Because all software is written using functions and classes. If you do not know how to pass data from class to class, to function you are not a programmer.