QSharedPointer<A> pA1(new A, &A::f);
QSharedPointer<A> pA1(new A, &A::f);
To copy to clipboard, switch view to plain text mode
This is a working example showing it calls the method with the correct this pointer:
#include <QtCore>
class Test
{
public:
Test() { qDebug() << "Constructed" << this; }
~Test() { qDebug() << "Destroyed" << this; }
void deleteThis() {
qDebug() << "Do this" << this;
// perform elaborate deletion ritual
delete this;
}
};
int main(int argc, char **argv)
{
QSharedPointer<Test> test1(new Test, &Test::deleteThis);
QSharedPointer<Test> test2(new Test, &Test::deleteThis);
QSharedPointer<Test> test3(test1);
test1.clear(); // no deletion, kept alive by test3
test2.clear();
return 0;
}
#include <QtCore>
class Test
{
public:
Test() { qDebug() << "Constructed" << this; }
~Test() { qDebug() << "Destroyed" << this; }
void deleteThis() {
qDebug() << "Do this" << this;
// perform elaborate deletion ritual
delete this;
}
};
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QSharedPointer<Test> test1(new Test, &Test::deleteThis);
QSharedPointer<Test> test2(new Test, &Test::deleteThis);
QSharedPointer<Test> test3(test1);
test1.clear(); // no deletion, kept alive by test3
test2.clear();
return 0;
}
To copy to clipboard, switch view to plain text mode
Edit: Hmm, how did I miss the update?
Bookmarks