I watched CppCon "Writing Good C++14... By Default" by Herb Sutter and on one of the slides was following piece of code:
auto p = make_shared<circle>(42);
auto v = load_shapes();
for(auto& s: v) {
if(s && *s == *p) {
cout << *s << "is a match\n";
}
}
My question is: why there is a
if(s && *s == *p)
check?
Can reference variable be nullptr ? If it can be, how can reference variable initialized by for each loop be nullptr ? Loop iterates over items, so in which case nullptr value can be assigned ? What are others possible values of reference variable that produces false if casted to bool?
Aucun commentaire:
Enregistrer un commentaire