[Cs3] Question regarding Lab3

Mikhail Nesterenko mikhail at cs.kent.edu
Thu Sep 9 14:58:05 EDT 2021


Tsung Heng Wu wrote:
> Hi Dr. Nesterenko,
> 
> For the Collection class, if the collection is empty, what should the
> last() function return? Because if I return NULL it would give a warning
> about implicit casting NULL to type T, which can cause problems. Right now
> my solution is to return a T random so it won't give warnings.


The standard says that the behavior of front() and end() on an empty
container is undefined. So we can assume that last() is undefined also.

However, people can define and implement

	 bool Collection::empty()

that returns true if the Collection is empty.

thanks,
-- 
Mikhail


More information about the cs3 mailing list