destructor

Destructor of class with pointer array C++

蓝咒 提交于 2019-12-22 08:26:07
问题 If I have a class with an array of pointers to another class Vehicle : class List { public: //stuff goes here private: Vehicle ** vehicles; } If I now write the destructor of the class List , do I manually iterate over the array (I know how many items are in the array) and delete every pointer to a vehicle, or will C++ automatically call the destructors of all the Vehicles in the array? (Like it does if there's a private string/... in the class or if it would be a STL container of Vehicle

VB6 Collection Remove Doesn't Fire Class_Terminate

血红的双手。 提交于 2019-12-22 07:02:34
问题 I apologize in advance; this is a long question. I've tried to simplify as much as I can but it's still a bit more long-winded than I'd care to see. In some legacy code, we've got a VB6 collection. This collection adds objects via the .Add method and removes them via the .Remove method. However, via tracing I can see that sometimes when the .Remove is called it appears that the class terminate for the object isn't called. But it's not consistent; it happens only rarely and I can't isolate the

Quick successful exit from C++ with lots of objects allocated

有些话、适合烂在心里 提交于 2019-12-22 06:56:08
问题 I'm looking for a way to quickly exit a C++ that has allocated a lot of structures in memory using C++ classes. The program finishes correctly, but after the final "return" in the program, all of the auto-destructors kick in. The problem is the program has allocated about 15GB of memory through lots of C++ class structures, and this auto-destruct process takes about 1 more hour itself to complete as it walks through all of the structures - even though I don't care about the results. The

Purpose of static_initialization_and_destruction and _GLOBAL__sub_I_main function in the assembly code for a C++ code?

假如想象 提交于 2019-12-22 05:53:18
问题 The following is the C++ source code. The code has a class HumanBeing and with Display and verify functions. Each function prints statements. #include <iostream> using namespace std; class HumanBeing { public: void display() { cout << "hello aam a human being" << endl; } void print() { cout << "verify print" << endl; } }; int main() { HumanBeing vamshi; vamshi.display(); vamshi.print(); return 0; } This is the corresponding assembly code of the above c++ code .file "verify.cpp" .local _ZStL8_

Explicitly invoking `int` destructor - why is a type alias required? [duplicate]

橙三吉。 提交于 2019-12-22 05:10:55
问题 This question already has an answer here : Pseudo-destructor call does not destroy an object (1 answer) Closed 2 years ago . The following program... int main() { int{1}.~int(); } does not compile on (see conformance viewer) : clang++ trunk, with -std=c++1z g++ trunk, with -std=c++1z CL 19 2017 Introducing a type alias for int ... int main() { using X = int; int{1}.~X(); } ...makes the program valid on all previously mentioned compilers, without warnings (see conformance viewer) . Why is a

Is it safe to delete a POD object by a pointer to its base?

痞子三分冷 提交于 2019-12-22 03:24:34
问题 Actually I am thinking about trivially destructible objects, not only about POD (I am not sure POD can have base class). When I read this explanation for is_trivially_destructible from cppreference I notice this: Storage occupied by trivially destructible objects may be reused without calling the destructor. So, it is safe to do that: struct A { int a; }; struct B : A { int b; }; int main() { A* a = new B; delete a; } B::~B() won't be called - and AFAIK (please correct if I am wrong) the

Destructor for a linked List

萝らか妹 提交于 2019-12-22 01:03:31
问题 I have a linked_list and currently my destructor is not working properly. Not entirely sure why. Can somebody explain me how to solve this? class linked_list { private: struct node { // String in this node std::string data; // Pointer to next node struct node *next; }; //First item in the list struct node *first; Here is my destructor linked_list::~linked_list(void) { while (first) { delete first; first = first->next; } } 回答1: The problem lies here: delete first; first = first->next; When you

Delete vector class member

ぃ、小莉子 提交于 2019-12-21 22:07:15
问题 I have a class A with a member which is a vector of object pointers of another class B class A { std::vector<B*> m_member_A m_member_A is populated by creating objects of B by using new operator B* b1 = new B; m_member_A.push_back(b1); In A's destructor, is the following correct to free up everything? A::~A() { for(int i = 0; i < m_member_A.size(); ++i) { delete m_member_A[i]; } m_member_A.clear(); } 回答1: It's correct, as long as you also have a correct copy constructor and copy-assignment

Can't find .dtors and .ctors in binary

喜夏-厌秋 提交于 2019-12-21 17:53:40
问题 I am reading the book Hacking, the art of exploitation. In the book there is a section that explain the use of .dtors and .ctors . I'm trying to reproduce one of the exercises of the book but in my executable I do not have this sections. At first I thought the problem was that I was compiling for 64-bit, but now I'm compiling for 32-bit and .dtors and .ctors are still not appearing in the section table. Here is the code: #include <stdio.h> #include <stdlib.h> static void miConstructor(void) _

Clearing controls from FlowLayoutPanel not calling destructors?

六月ゝ 毕业季﹏ 提交于 2019-12-21 17:27:42
问题 Sorry if I'm missing something obvious, but I'm trying to clear the controls (a series of user controls) from a FlowLayoutPanel - (panelName).Controls.Clear();. Unfortunately this doesn't seem to be calling the destructors for the objects on the panel - the User Objects column in the task manager just keeps going up and up, until it hits 10,000 and throws an excecption. Does anyone know what I'm missing here? 回答1: Not a solution, but a workaround - the objects do seem to be destroyed by this