Exercises






Exercises

Exercise 1

For each of the following errors, write a simple test case containing the error, and try to compile it. In the error messages, look for the key words that relate to the error in the code.

  1. Calling bind with a placeholder argument that tries to use an argument that is past the implementation's maximum allowed value.

  2. Calling bind with fewer or more arguments than the callable object takes. (You may have to call the returned object to get an error message.)

  3. Calling an object returned by bind with a literal value instead of an lvalue.

  4. Calling bind with a first argument that is not a callable object. (You may have to call the returned object to get an error message.)

Exercise 2

Write a program that calls bind, passing a pointer to the standard library function cosf and the value 1.0f, and calls the resulting callable object with no arguments. Show the result.

Exercise 3

Write a program that calls bind, passing a pointer to the standard library function cosf and the placeholder _1, and calls the resulting callable object with an argument that is a variable of type float holding the value 1.0f.

Exercise 4

Write a program that calls bind, passing a pointer to the standard library function cosf and the placeholder _2, and calls the resulting callable object with two arguments. The second argument should be a variable of type float holding the value 1.0f.

Exercise 5

Write a program that defines a type named employee with a public member function named ID that takes no arguments and returns a value of type int. The constructor for employee should set the value that will be returned by ID. Create a callable object whose function call operator returns TRue for all employee objects whose ID is greater than 10. This takes two steps: Call bind to bind the member function ID to the employee object that will be passed to the function call operator (use _1 to refer to that object), and call bind again to pass that result and the value 10 to the standard library class template less. Create a TR1 array of employee objects, and use the standard algorithm count_if to count the number of employees whose ID is greater than 10.

Exercise 6

Using the employee type from the previous example, write a program that sorts a standard library vector object that holds employee objects so that the contained objects are in order according to their ID values.



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows