Quote:Original post by indigox3
In other words v is a vector of pointers, not objects
Well, pointers don't have destructors, so nothing happens to what they point to when the vector and its elements get destroyed.
Quote:Original post by indigox3
In other words v is a vector of pointers, not objects
Quote:Original post by Anonymous Poster
Wow - what a lot to say very little, still it probably felt intelligent at the time.
More simply, vectors allocate and deallocate memory as required.
If adding objects to a vector like in your example, the vector will allocate memory (on the heap using new) and make copies of your objects. Unless you're using a very old implementation of STL that contains such a bug, it's not a bug in STL. Certainly not one i've encountered anyway.
Quote:Original post by indigox3
Along those lines, ~vector() calls _Tidy() calls allocator::deallocate() calls delete with the pointer to the first element of the vector as an argument.
Quote:Original post by FrunyQuote:Original post by indigox3
In other words v is a vector of pointers, not objects
Well, pointers don't have destructors, so nothing happens to what they point to when the vector and its elements get destroyed.
class A : public B{public:A(){}~A(){}std::vector<int> mInt;};main(){A* a = new A();a->mInt.push_back(12);delete a;}
Quote:Original post by indigox3Quote:Original post by FrunyQuote:Original post by indigox3
In other words v is a vector of pointers, not objects
Well, pointers don't have destructors, so nothing happens to what they point to when the vector and its elements get destroyed.
I'm totally confused by this. operator delete takes only pointers as arguments.
#include <iostream>class Boring { public: Boring() { std::cout << "Construct me!" << std::endl; } Boring(const Boring &) { std::cout << "Construct me!" << std::endl; } ~Boring() { std::cout << "Destroy me!" << std::endl; }};int main(int, char **) { Boring ** pointer_to_pointer = new Boring *; // creates a new Boring pointer *pointer_to_pointer = new Boring; // creates a new Boring delete pointer_to_pointer; // deletes the pointer, does nothing to the Boring // and causes a mem leak return 0;}
Quote:Original post by SiCrane
As you can see, deleting the pointer does nothing to delete the object pointed to by the pointer.
delete pointer;
delete pointer_to_pointer;
class __declspec( dllexport ) A // forgot the "__declspec(dllexport)" last time!{public:A();~A();std::vector<int> aaa;void push() { aaa.push_back(1);}};
int func(){ A* a = new A; a->aaa.push_back(1); //a->push(); // if this line is used instead of the above line no crash delete a; //crash here. }