Function objects are used extensively in the STL. One important use for them is as arguments to certain algorithms. They allow you to customize the operation of these algorithms. The class, however, has no data and only one member function, which is the overloaded operator. The class is often customized so it can work with different types.
1. The predefined STL function objects, located in the functional header file. There are function objects corresponding to all the major C++ operations. There are function objects for arithmetic operations, comparisons, and logical operations.
2. Custom function objects if one of the standard function objects doesn’t do what you want, you can write your own. Storing pointers is a good way to improve efficiency, especially for large objects, because it avoids the copying process that takes place whenever an object is placed in a container.
Function objects can also modify the behavior of containers. In some cases the same function is available as both an algorithm and a member function.
1. The predefined STL function objects, located in the functional header file. There are function objects corresponding to all the major C++ operations. There are function objects for arithmetic operations, comparisons, and logical operations.
2. Custom function objects if one of the standard function objects doesn’t do what you want, you can write your own. Storing pointers is a good way to improve efficiency, especially for large objects, because it avoids the copying process that takes place whenever an object is placed in a container.
Function objects can also modify the behavior of containers. In some cases the same function is available as both an algorithm and a member function.

0 comments:
Post a Comment