Hi there,
I have a program in my C++ application, so I developed a simple example to explain the problem:
Main
#include <QtCore/QCoreApplication>
#include "myinterface.h"
#include "myconcreteclass.h"
int main(int argc, char *argv[])
{
MyInterface *myConcreteObject = new MyConcreteClass();
myConcreteObject->doSomething();
qDebug("Delete myConcreteObject");
delete myConcreteObject;
return a.exec();
}
#include <QtCore/QCoreApplication>
#include "myinterface.h"
#include "myconcreteclass.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
MyInterface *myConcreteObject = new MyConcreteClass();
myConcreteObject->doSomething();
qDebug("Delete myConcreteObject");
delete myConcreteObject;
return a.exec();
}
To copy to clipboard, switch view to plain text mode
MyInterface
#ifndef MYINTERFACE_H
#define MYINTERFACE_H
class MyInterface
{
public:
virtual void doSomething() = 0;
};
#endif // MYINTERFACE_H
#ifndef MYINTERFACE_H
#define MYINTERFACE_H
class MyInterface
{
public:
virtual void doSomething() = 0;
};
#endif // MYINTERFACE_H
To copy to clipboard, switch view to plain text mode
MyConcreteClass
// Header
#ifndef MYCONCRETECLASS_H
#define MYCONCRETECLASS_H
#include "myinterface.h"
class MyConcreteClass : public MyInterface
{
public:
MyConcreteClass();
~MyConcreteClass();
void doSomething();
};
#endif // MYCONCRETECLASS_H
// Body
#include "myconcreteclass.h"
#include <QDebug>
MyConcreteClass::MyConcreteClass()
{
qDebug("Concrete class constructor");
}
MyConcreteClass::~MyConcreteClass()
{
qDebug("Concrete class destructor");
}
void MyConcreteClass::doSomething()
{
qDebug("Do something");
}
// Header
#ifndef MYCONCRETECLASS_H
#define MYCONCRETECLASS_H
#include "myinterface.h"
class MyConcreteClass : public MyInterface
{
public:
MyConcreteClass();
~MyConcreteClass();
void doSomething();
};
#endif // MYCONCRETECLASS_H
// Body
#include "myconcreteclass.h"
#include <QDebug>
MyConcreteClass::MyConcreteClass()
{
qDebug("Concrete class constructor");
}
MyConcreteClass::~MyConcreteClass()
{
qDebug("Concrete class destructor");
}
void MyConcreteClass::doSomething()
{
qDebug("Do something");
}
To copy to clipboard, switch view to plain text mode
Output
Concrete class constructor
Do something
Delete myConcreteObject
... why the program didn't called the destructor of myConcreteClass?
Sorry for my english
Thanks, Dario
Bookmarks