NavigationUser loginSpam?See spam posts on this site? If so, please don't reply to the spam! Instead, just report the URL to the webmaster. |
using vector and primitives(A c++ question) Hello, I made a vector: std::vector bingo= new vector(100) When I say bingo.clear(), will it really free the memory of all those ints? In fact, my main problem is that i don't know how the primitives like int, long, float and double are handled in C++. In the case from above, are they dynamicaly allocated? How to clear them? Also, in case i have class objects that I want to put in a vector, will the clear() function automatically call their destructors, or do i need to do it manually? |
all depends...
If you're unsure, write a small test program and run it under a memory test program... hmmm... so long since I've done that I can't remember the name of the program.
If you store a copy of the objects, they will be destroyed when you call clear. If you store a pointer to objects, the pointer will be destroyed (but not the object).
You never explicitly call an object's destructor; it is the compiler's job to put in calls to the destructor and this is usually done when a declared object goes out of scope, or if an object created by 'new' has 'delete' called on its pointer.
Does that mean that clear()
Does that mean that clear() will destroy a pointer without asking it to self-destruct (by calling delete object)?
BTW, this confusion comes from using Java for quite a time, where you can simply forget about most of similar issues, and then switching to C++ again.