I am new to C ++, so I try to develop many Java isms during training. In any case, in Java, if I had a class with a search method that would return a T object from Collection< T > that matched a specific parameter, I would return that object and if the object was not found in the collection, I will return null . Then in my calling function I would just check if(tResult != null) { ... }
In C ++, I find that I cannot return null if the object does not exist. I just want to return an “indicator” of type T, which notifies the calling function that the object was not found. I do not want to throw an exception, because this is not an exceptional circumstance.
Here's what my code looks like right now:
class Node { Attr& getAttribute(const string& attribute_name) const {
How can I change it so that I can specify this marker?
c ++ return-value sentinel
aduric Apr 14 '10 at 16:41 2010-04-14 16:41
source share