Item 37. Forward Declarations

I l @ ve RuBoard

Difficulty: 3

Forward declarations are a great way to eliminate needless compile-time dependencies. But here's an example of a forward-declaration snare . How would you avoid it?

  1. Forward declarations are very useful tools. In this case, they don't work as the programmer expected. Why are the marked lines errors?

     // file f.h // class ostream;  // error class string;   // error string f( const ostream& ); 
  2. Without including any other files, write the correct forward declarations for ostream and string above.

I l @ ve RuBoard


More Exceptional C++
More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions
ISBN: 020170434X
EAN: 2147483647
Year: 2001
Pages: 118
Authors: Herb Sutter

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net