I'm trying to us Qt for WebAssembly. I'm using QVector, but I want to add some convenient finder methods. So I've tried subclassing like the code below. The compiler complains that vec.begin() and vec.end() do not exist. If I change vec from a Foo_Vector to a QVector (no subclassing), it works.
Other methods from QVector also become undefined when using the subclass version -- such as size.
I tried defining a method on Foo_Vector:
size_t size() const { return QVector<Foo>::size(); }
That produces an error about non-static methods. So I tried to do this:
QVector<Foo> * ptr = static_cast<QVector<Foo>>(this);
And that produces an error that there's no conversion from a Foo_Vector * to a QVector *.
Does anyone have an explanation? Do I have to do this through composition instead and implement passthrough methods for anything I want to do?
#include <QCoreApplication>
#include <QVector>
class Foo {
public:
int a;
int b;
};
class Foo_Vector: public QVector<Foo> {
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Foo_Vector vec;
for (auto it = vec.begin(); it != vec.end(); ++it) {
}
return a.exec();
}