vendredi 18 janvier 2019

Difference in assignment/initialization of shared pointer

We can initialize a shared_pointer in three ways.

1. shared_ptr<int>p(new int(8));
2. shared_ptr<int>p=shared_ptr<int>(8);
3. shared_ptr<int>p=make_shared<int>(8);

We know 3rd statement has an advantage over 1st statement, in terms of single operation initialization and exception handling support.

Is there any difference between 1st and 2nd statements according to exception thrown, performance etc..

Aucun commentaire:

Enregistrer un commentaire