What is the difference between a forward declaration and including a header? When can you forward declare?
Last updated
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.