Exercises
-
18.3 (Operator Overloads in Templates) Write a simple function template for predicate function
isEqualTo
that compares its two arguments of the same type with the equality operator (==
) and returnstrue
if they are equal andfalse
otherwise. Use this function template in a program that callsisEqualTo
only with a variety of fundamental types. Now write a separate version of the program that callsisEqualTo
with a user-defined class type, but does not overload the equality operator. What happens when you attempt to run this program? Now overload the equality operator (with the operator function)operator==
. Now what happens when you attempt to run this program? -
18.4 (
Array
Class Template) Reimplement classArray
from Figs.
Get C++ How to Program, 10/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.