0

What is the Difference between Forwarded declaration and Include Header files?

When I should use Forwarded Declaration and when I should use Header Files?

Because I got sometimes it is preferred to use Forwarded declaration and sometimes it is preferred to include the files.

Fareanor
  • 5,900
  • 2
  • 11
  • 37
  • 1
    My recommendation: use forward declaration *when possible*, otherwise include header. – prapin Oct 04 '21 at 10:20
  • Use forwarded declarations when possible. Consider using header-header files (`*.hh`) which just provides the forward declarations of the associated header files (`*.h`). Follow the *include what you use* rule, and never depend on indirect includes. – Eljay Oct 04 '21 at 11:01
  • When you just need pointer, use forward declaration. When you need info from the type (method, field), include header. – Jean-Baptiste Yunès Oct 04 '21 at 11:09

0 Answers0