I have a function defined as follows:
void foo(std::shared_ptr<X> x) { ... };
If I declare a shared ptr to X:
std::shared_ptr<X> sourcePtr(new X(...));
I can then call foo as follows:
foo(std::move(sourcePtr));
or
foo(sourcePtr);
I understand that if I use the first option then sourcePtr becomes null. Does it also prevent the reference count from being incremented?
If that doesn't matter, which option should I prefer? Should I be considering anything else when making such a decision?
Aucun commentaire:
Enregistrer un commentaire