View Full Version : Why the destrcutors in some Qt abstract classes are not virtual?
legendwan
1st September 2010, 05:28
For example, in QAbstractItemModel.h, the destructor of class QAbstractItemModel is virtual, while the destructor of class QAbstractTableModel and QAbstractListModel are not virtual? :confused:
I use Qt library V4.6.2.
lyuts
1st September 2010, 07:41
There is no keyword 'virtual' but the destructors are virtual, because these classes inherit QAbstractItemModel whose destructor is virtual.
Consider this code:
class Base
{
public:
virtual void f() { std::cout << "Base::f" << std::endl; }
};
class Derived : public Base
{
public:
void f() { std::cout << "Derived::f" << std::endl; }
};
int main(int argc, char **argv)
{
Base *base = new Derived();
base->f();
}
You'll get "Derived::f" printed. At least I'm getting this result :).
legendwan
1st September 2010, 09:21
Yes. I got it. Thank you, lyuts!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.