mercredi 25 mars 2015

Array of shared pointers that point to struct elements, what kind of a syntax?

I need an array a size of n that has shared pointers and each of those point to one struct element. What is the syntax?


Is it just



shared_ptr<Struct_name> array(new Struct_name(n));


or something else?


Should I use C++ array (#include array) instead of C array?


And what about releasing the memory when there is no need for the array anymore? Do smart pointers handle it for arrays also or do I have to delete every array element by



delete array[i]

Aucun commentaire:

Enregistrer un commentaire