lundi 16 mars 2020

Can a smart pointer passed by reference be a nullptr?

There are many questions about passing smart pointers by reference. What I did not find is a definite answer on: Can we pass a nullptr to a method accepting a smart pointer by reference?

Example:

void myFunc(std::shared_ptr<std::string> &myStrRef) {
   // do something
}

void main() {
   myFunc(nullptr);
}

Aucun commentaire:

Enregistrer un commentaire