What is the difference between a forward declaration and including a header? When can you forward declare?

Last updated 21 June 2026

  • A forward declaration (class Widget;) creates an incomplete type (name only, no layout). It cuts compile dependencies and breaks include cycles.

  • It suffices for pointers, references, and function declarations that take or return the type.

  • Include the header when a complete type is needed: accessing members, by-value data members, inheritance, sizeof, or instantiation.

  • https://www.sandordargo.com/blog/2024/05/15/when-includes-are-needed
  • https://andreasfertig.com/blog/2025/10/forward-declaring-a-type-in-cpp-the-good-and-the-bad/
  • https://stackoverflow.com/questions/2832714/header-files-inclusion-forward-declaration
All C++ interview questions