Wednesday, November 3, 2010

Forward Declarations

If a forward declaration of a class will you allow to compile a file, you should not include the corresponding header file.

This reduces the dependencies. This typically works when you only need the declaration and not the definition (sometimes just for the size) of the class. When you implement the Pimpl Pattern, your class can contain a pointer the the implementation of your class. Instead of including the header file for the implementation, only a forward declaration would be needed.

Reference: Exceptional C++ by Herb Sutter. Addison-Wesley, 1999, p. 102.

No comments:

Post a Comment