Category : destructor

In my class I wrote the following d’tor: template<class T> void avl_tree<T>::deallocate_node(const node<T> *ptr) const { if (ptr == nullptr) return; deallocate_node(ptr->left_node); deallocate_node(ptr->right_node); delete ptr; } template<class T> avl_tree<T>::~avl_tree() { deallocate_node(root); } Can I replace it with one function? (As I read something similar) Source: Windows Que..

Read more

In my code, the destructor is called right after the object it created token_value = value(TYPE_ARRAY, malloc(sizeof(value) * MAX_VALUE_STR_LEN)); Immediately after this line of code, the destructor is called. However, token_value the function nor program ended, no delete operator was called, and the scope containing token_value has not ended to the best of my knowledge. ..

Read more

I have encountered this runtime exception at the very end of the program by simply creating an instance of the specified class, so I presume the issue lies with either the constructor, copy constructor, copy assignment operator or destructor. I have read up on and followed the rule of three to the extent of my ..

Read more

#include <iostream> #include <cstring> class Foo { public: uint32_t m_Size; char *m_Data; public: Foo() = default; Foo(const char *pieceOfString) { printf("Foo Created!n"); m_Size = strlen(pieceOfString); m_Data = new char[m_Size]; memcpy(m_Data, pieceOfString, m_Size); } ~Foo() { printf("Deleted Foo. "); delete[] this->m_Data; } }; class Entity { public: Foo m_Name; public: Entity(const Foo &name){ this->m_Name=name; } ~Entity(){ ..

Read more

В моей программе есть два класса List, OrderedList. В exe.cpp создаю три объекта типа OrderedList, заполняя данными из файла. В OrderedList переопределён опреатор + и ^, на объединение и пересечение списков. В этих методах создается результирующий OrderedList, который уничтожается деструктором в конце блока этого метода. То есть в exes.cpp приходит nullptr. Вроде не ошибаюсь. Как ..

Read more