Поясните по хардкору, почему список при деструктурировании не деструктит шаред поинтеры расположенные в нем
#include <QList>
#include <QSharedPointer>
#include <iostream>
#define LAFAFA 3
class Object {
int data;
public:
Object(int a) : data(a) {
std::cout << "Object contstructed i: " << a << std::endl;
};
Object(const Object &cp) {
this->data = cp.data;
std::cout << "Object copied i: " << cp.data << std::endl;
}
~Object() {
std::cout << "Object desctructed i: " << this->data << std::endl;
};
void print() {
std::cout << "Object i: " << this->data << std::endl;
};
};
int main (int argc, char ** argv) {
{
std::cout << std::endl;
std::cout << "=========== Just Objects ===================" << std::endl;
QList<Object> one;
for (int i=0; i < LAFAFA; i++) {
one.append(Object(i));
}
std::cout << "<<<< cycle finished" << std::endl;
};
{
std::cout << std::endl;
std::cout << "============ Shared pointers ===============" << std::endl;
QList<QSharedPointer<Object> > fuck;
for (int i=0; i < LAFAFA; i++) {
fuck.append(*(new QSharedPointer<Object>(new Object(i))));
};
std::cout << "<<<< cycle finished" << std::endl;
};
{
std::cout << std::endl;
std::cout << "============ Test Shp ======================" << std::endl;
QSharedPointer<Object> test = QSharedPointer<Object>(new Object(10));
}
};
=========== Just Objects ===================
Object contstructed i: 0
Object copied i: 0
Object desctructed i: 0
Object contstructed i: 1
Object copied i: 1
Object desctructed i: 1
Object contstructed i: 2
Object copied i: 2
Object desctructed i: 2
<<<< cycle finished
Object desctructed i: 2
Object desctructed i: 1
Object desctructed i: 0
============ Shared pointers ===============
Object contstructed i: 0
Object contstructed i: 1
Object contstructed i: 2
<<<< cycle finished
============ Test Shp ======================
Object contstructed i: 10
Object desctructed i: 10
Destroys the list. References to the values in the list and all iterators of this list become invalid.