figure shows minimal implementation and also illustrates the widely used idiom for providing an output function for new class type the idiom is to provide public member functionnamed printthat takes an ostream as parameter that public member function can then be called by globalnonclass functionoperator<<that accepts an ostream and an object to output function objects in section we showed how function templates can be used to write generic algorithms as an examplethe function template in figure can be used to find the maximum item in an array howeverthe template has an important limitationit works only for objects that have an operatorfunction definedand it uses that operatoras the basis for all comparison decisions in many situationsthis approach is not feasible for instanceit is stretch to presume that rectangle class will implement operator<and even if it doesthe compareto method that it has might not be the one we want for instancegiven by- rectangle and -by- rectanglewhich is the larger rectanglethe answer would depend on whether we are using area or width to decide or perhaps if we are trying to fit the rectangle through an openingthe larger rectangle is the rectangle with the larger minimum dimension as second exampleif we wanted to find the maximum string (alphabetically lastin an array of stringsthe default operatordoes not ignore case distinctionsso "zebrawould be considered to precede "alligatoralphabeticallywhich is probably not what we want third example would occur if we had an array of pointers to objects (which would be common in advanced +programs that make use of feature known as inheritancewhich we do not make much use of in this textthe solutionin these casesis to rewrite findmax to accept as parameters an array of objects and comparison function that explains how to decide which of two objects is the larger and which is the smaller in effectthe array objects no longer know how to compare themselvesinsteadthis information is completely decoupled from the objects in the array an ingenious way to pass functions as parameters is to notice that an object contains both data and member functionsso we can define class with no data and one member functionand pass an instance of the class in effecta function is being passed by placing it inside an object this object is commonly known as function object figure shows the simplest implementation of the function object idea findmax takes second parameterwhich is generic type in order for the findmax template to expand without errorthe generic type must have member function named islessthanwhich takes two parameters of the first generic type (objectand returns bool otherwisean error will be generated at line when the template expansion is attempted by the compiler at line we can see that findmax is called by passing an array of string and an object that contains an islessthan method with two strings as parameters +function objects are implemented using this basic ideabut with some fancy syntax firstinstead of using function with namewe use operator overloading instead of the function being islessthanit is operator(secondwhen invoking operator()