I know that the answer will be obvious, probably not, but I'm just not completely sure.
For example somewhere it code in class/struct a have vector with objects in my case is Asset:
class Asset {
int ID = - 1;
}
std::vector<Asset> GAssets;
And then i also have function that retrive asset by its ID. If asset is found i can return it by reference to modify its actually content inside somewhere in my code, but if asset not found i need to return invalid asset with ID -1. To do this i basically can return new stack object, but here my problem, i think how this would work? It return my asset that it found is right but in case with invalid asset and new stack object, it removes it form stack or return it?
Asset& GetAssetByID(int ID) {
for(Asset& asset : GAssets) {
if(asset.ID == ID)
return asset;
}
return Asset(-1); // How this would returns?
}
NOTE: I'll tell you right away I could use pointers, but I don't need them because there are a lot of assets and I don't know when I will need to delete them. It's the same with smart pointers.