dimanche 31 octobre 2021

How to initialize an array of objects with a shared pointer

I am tryind to do something like this

struct car
{
    car(int a) : name(a) {}
    int val;
};

int main()
{
    std::map<int, std::shared_ptr<car[]>> mp;

    auto t = std::shared_ptr<car[]>(new car[100]); // Error car requires a paremeter.
}

My question is how do I pass 1 to every constructor? The following does not work

auto t = std::shared_ptr<car[]>(new car[100](1)); 

Aucun commentaire:

Enregistrer un commentaire