QList of derived classes
-
Hello
In C++11 have been implemented unique pointers. So with C++11 I can do sth like this:
@#include <iostream>
#include <vector>
#include <memory>
struct Base {
virtual void f() { std::cout << "Base\n"; }
virtual ~Base(){}
};
struct Derived : Base {
void f() { std::cout << "Derived\n"; }
};
int main()
{
std::vector<std::unique_ptr<Base>> v;
v.emplace_back(new Derived);
v[0]->f();
}@I can create a list\vector with unique pointers for base class and then add elements of derived classes to it. Can I do the same in Qt? Has Qt implemented smart pointers? Or maybe I should use C++11 std::vector?
-
Hi,
Currently you could create a QList or QVector of std::unique_ptr. AFAIK there's no equivalent in Qt for the unique_ptr type.