destructor

destructors in Qt4

I'm very confused about using destructors in Qt4 and hope, you guys can help me. When I have a method like this (with "Des" is a class): void Widget::create() { Des *test = new Des; test->show(); } how can I make sure that this widget is going to be deleted after it was closed? And in class "Des" i have this: Des::Des() { ...

Qt library destructor Question

Im new to the Qt library and i was going through the demonstrations. I came across this class without a destructor.... this is the cpp file http://doc.trolltech.com/4.5/demos-mainwindow-mainwindow-cpp.html and here is the .h file http://doc.trolltech.com/4.5/demos-mainwindow-mainwindow-h.html the constructor uses the new operator but ...

C++ - when are non-pointers class member destroyed?

Suppose I have this code... class GraphFactory : public QObject { private: QMap<QString, IGraphCreator*> factory_; public: virtual ~GraphFactory(); }; GraphFactory::~GraphFactory() { // Free up the graph creators QMap<QString, IGraphCreator*>::iterator itr; for (itr = factory_.begin(); itr != factory_.end(); itr++)...

Unusual destructor behaviour when copying over stack variables

I wrote a test to check whether destructors were called before an overwriting assignment on a stack variable, and I can't find any rational explanation for the results... This is my test (in Visual C++ 2008 Release mode): #include <iostream> class C { public: char* ptr; C(char p) { ptr = new char[100]; ptr[0] = p;} ~C() { std::cout ...

C++ GCC 4.3.2 error on vector of char-array

Hello, It is similar in problem to this bug http://stackoverflow.com/questions/1468058/question-about-storing-array-in-a-stdvector-in-c but for a different reason (see below). For the following sample program in C++: #include <vector> int main(int c_, char ** v_) { const int LENGTH = 100; std::vector<char[LENGTH]>...

Questions about C++ memory allocation and delete

I'm getting a bad error. When I call delete on an object at the top of an object hierarchy (hoping to the cause the deletion of its child objects), my progam quits and I get this: *** glibc detected *** /home/mossen/workspace/abbot/Debug/abbot: double free or corruption (out): 0xb7ec2158 *** followed by what looks like a memory dump of...

VB6 Collection Remove Doesn't Fire Class_Terminate

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 w...

C++ stack allocated object, explicit destructor call

Hi, I came across a strange use of the destructor while working on an existing library. The destructor of a stack allocated stl vector was being called explicitly, when its the case that that object may need to be used again. These vector objects are a slightly customised version of the stl vector class that have a specialized clear met...

Why don't STL containers have virtual destructors?

Does anyone know why the STL containers don't have virtual destructors? As far as I can tell, the only benefits are: it reduces the size of an instance by one pointer (to the virtual method table) and it makes destruction and construction a tiny bit faster. The downside is that it's unsafe to subclass the containers in the usua...

Expected contructor, destructor, or type conversion before '<' token

From what I can gather from Google, I must have syntax/parsing error but I can't seem to locate it.. This is my header file: #include <fstream> #include <iostream> #include <vector> #ifndef DATA_H #define DATA_H #include "Data.h" #endif vector<Data*> DataReader(); // This is line 11, where the error is.. And this is the .cpp fil...

How to check if memory has aready been released in Destructor?

I have a simple tank wars style game using the allegro open source library. In my tank class, I initialize arrays of pointers to bitmap objects to 0. Then I create new objects with an allegro function create_bitmap which allocates the memory and initializes it. Then I go about my business as usual. The problem is, when I go to releas...

Destructor of a concrete class

Guideline #4 link text, states: A base class destructor should be either public and virtual, or protected and nonvirtual. Probably I'm missing something, but what if I just create a concrete class, that is not designed to be used as base class. Should I declare it's destructor public and virtual? By this I'm implicitly declate...

Explicitly calling a destructor in a signal handler

I have a destructor that performs some necessary cleanup (it kills processes). It needs to run even when SIGINT is sent to the program. My code currently looks like: typedef boost::shared_ptr<PidManager> PidManagerPtr void PidManager::handler(int sig) { std::cout << "Caught SIGINT\n"; instance_.~PidManagerPtr(); //PidManager is a...

C++ Constructor and Destructor

I'm getting some errors when compiling my program. They relate to the constructor and destructor of my class Instruction. Errors are: /tmp/ccSWO7VW.o: In function `Instruction::Instruction(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)': ale.c:(.text+0x241): undefined reference to `vtable for Instruction' ...

Does a destructor always get called for a delete operator, even when it is overloaded?

I'm porting a bit of an old code from C to C++. The old code uses object-like semantics, and at one point separates object destruction from freeing the now-unused memory, with stuff happening in between: Object_Destructor(Object *me) { free(me->member1), free(me->member2) } ObjectManager_FreeObject(ObjectManager *me, Object *obj) { fre...

Server crash due to ASP.NET-Page (C#)

My local test server crashes as soon as I'm trying to write to a logfile. I'm using this for an ASP.NET-Page, codebehind is C#. Structure: / Functions.cs index.aspx index.aspx.cs I create an instance of Functions as my index.aspx loads. In Functions, I define a function for logging, which is called from index.aspx.cs and looks lik...

Why can't static classes have destructors?

Two parts to this: If a static class can have a static constructor, why can't it have a static destructor? What is the best workaround? I have a static class that manages a pool of connections that are COM objects, and I need to make sure their connections get closed/released if something blows up elsewhere in the program. ...

Why is my Destructor getting called?

I have a few classes that hold references to other classes through IDictionary instance members. Like so: class A { private readonly Dictionary<int, B> _particles = new Dictionary<int, B>(); public void CreateNewB(int someInt) { var b = new B(); if (!_particles.ContainsKey(someInt) _particles.Add(someInt, b); ...

C++ destruction of temporary object in an expression

Given the following code: #include <iostream> struct implicit_t { implicit_t(int x) : x_m(x) { std::cout << "ctor" << std::endl; } ~implicit_t() { std::cout << "dtor" << std::endl; } int x_m; }; std::ostream& operator<<(std::ostream& s, const implicit_t& x) { return s << x.x_m;...

Baseclass Virtual Destructor Access Violation

Sorry if this was asked already, but I had a hard time searching for destructor and access violation =) Here's C++ pseudo-code the scenario: In DLL1 (compiled with /MT) class A { public: virtual ~A() <== if "virtual" is removed, everthing works OK { } } class B : public A { public: __declspec( dllexport ) ~B() ...