On 10/26/06, Genjix <[EMAIL PROTECTED]> wrote: > I'm not too clear how csArrayCmp can be used.
csArrayCmp is a class which encapsulates both the key for which you want to search and the function which knows how to compare that key against an element in the array. When you want to search for a particular element in an array, you pass an instance of csArrayCmp to csArray<>::FindKey(), FindSortedKey(), etc. > Do I pass in a functor object as > the second argument in the constructor... then what? The second argument to the csArrayCmp is a function which knows how to compare the supplied key (first argument) against an array element. If the compiler already knows how to compare your key against an array element, then you don't need to supply the second argument. This is true for many types, such as numbers, strings, simple structures, etc. Typically, the only time you need to supply the second argument is when the compiler's default comparison mechanism is inappropriate or when the key is only a subset of the element type stored in the array. For instance, if you are searching the 'name' field in an array of elements of type 'struct Person', you would supply a comparison function which knows how to extract the 'name' from a 'Person' in order to perform the comparison. > How does csArray know what the key value is inside an object? csArray itself never cares about the key stored inside the csArrayCmp instance. Instead, it merely asks csArrayCmp if an element of the array matches the supplied key. The key and the manner in which the key is compared against an array element are encapsulated and hidden from csArray. -- ES ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Crystal-main mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/crystal-main Unsubscribe: mailto:[EMAIL PROTECTED]
