Return a “NULL” object if search result not found
In C++, references can’t be null. If you want to optionally return null if nothing is found, you need to return a pointer, not a reference: Attr *getAttribute(const string& attribute_name) const { //search collection //if found at i return &attributes[i]; //if not found return nullptr; } Otherwise, if you insist on returning by reference, then … Read more