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()
{
...
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 ...
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++)...
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 ...
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]>...
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...
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...
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...
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...
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...
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...
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...
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...
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'
...
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...
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...
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.
...
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);
...
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;...
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() ...