Is it possible to have a QList of QScopedPointer of some abstract class?

679 Views Asked by At

I want to have a QList or QVector in a class that it has a constant number of element type QScopedPointer< SomeAbstractClass >. I could easily use something like this:

QList<QScopedPointer<SomeClass> listClass;
listClass.append(QScopedPointer<SomeClass>(new SomeClass()));

But in QScopedPointer, copy constructor is disabled and we can't instantiate an abstract class.

Off course I could easily use QSharedPointer but for some reasons I don't want to do that, so what can I do?

Edit: Here is my sample code, and I got this error:

class someAbsClass{
    public:
        someAbsClass(){}
        virtual void fcn()=0;
    };

    class someClass : public someAbsClass{
    public:
        someClass(){}
        void fcn(){
            std::cout << "fcn" << std::endl;
        }
    };


    int main(){
        QVector<QScopedPointer<someAbsClass> > VectorPtrAbss(1);
        VectorPtrAbss[0].reset(new someClass());
    }

error: 'QScopedPointer<T, Cleanup>::QScopedPointer(const QScopedPointer<T, Cleanup>&) [with T = someAbsClass; Cleanup = QScopedPointerDeleter<someAbsClass>]' is private
 Q_DISABLE_COPY(QScopedPointer)
                ^
0

There are 0 best solutions below