Bruce Eckel's Thinking in C++, 2nd Ed Contents | Prev | Next

answers:

  1. 1. Why is function overloading absolutely necessary in C++?

    A: Because objects must be initialized through constructors, which have the same name as the class. You may need to initialize an object in more than one way, so you must be able to overload the constructor by using it's name more than once.

  2. 2. How do you prevent global names from being decorated? That is, how do you bring global names in so you can use existing C libraries without worrying that their names will get decorated, and the linker won't be able to find them as a result?
  3. 3. What is the difference between function overloading and default arguments?
Make vartype a regular and public enumeration (with no instance) and modify print( ) so it requires a vartype argument to tell it what to do.

  1. Implement Mem2.h and make sure that the modified class still works with MemTest.cpp.
  2. Use class Mem to implement Stash. Note that, because the implementation is private and thus hidden from the client programmer, the test code does not need to be modified.
  3. In class Mem , add a bool moved( ) member function that takes the result of a call to pointer( ) and tells you whether the pointer has moved (due to reallocation). Write a main( ) that tests your moved( ) member function. Does it make more sense to use something like moved( ) or to simply call pointer( ) every time you need to access the memory in Mem?
Contents | Prev | Next


Contact: webmaster@codeguru.com
CodeGuru - the website for developers.
[an error occurred while processing this directive]