mercredi 7 août 2019

How to have a generic vector inside a class for which the type is unknown

I want to have an array class using a vector where type of vector is to be decided by user.

class Array {
    vector<type> V
    int size;
    string type;
public:
    Array() {
        this->size = 0;
        this->type = "void";
        // V = vector<depending_on_type>(size);
    }

    Array(int size, string type) {
        this->size = size;
        this->type = type;
        if(type == "int") {
            // initialize as vector<int>
        }
    }
}

I tried using pointers and pointers to pointers but nothing works so far.

Aucun commentaire:

Enregistrer un commentaire