J
J
Junior0072016-09-13 22:44:56
Programming
Junior007, 2016-09-13 22:44:56

How to write a function that may not return a value?

For example, there is a search function that looks for an object in an array and returns the first one found, but what should it return if it does not find anything?

Object& find (Object o)
{
    /* Поиск, если нашли */
   return link;
   /* Если не нашли? */
   return NULL; // - Нельзя
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2016-09-13
@Junior007

Object* find (const Object& o)
{
    /* Поиск, если нашли */
   return link;
   /* Если не нашли? */
   return NULL; // Теперь можно
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question