-2

I currently started programming in C++. My question is, whether when Im working with Lists I have to include this as a header file etc.? Im working with this reference: https://www.cplusplus.com/reference/list/list/

How can I know when I have to include something as a header file in general?

Thanks in advance.

Jazzl
  • 17
  • 4
  • 2
    Related: https://stackoverflow.com/questions/26614983/which-headers-in-the-c-standard-library-are-guaranteed-to-include-another-head Generally you'll know what is necessary to be `#include`d from the [documentation](https://en.cppreference.com/). Doesn't your reference state that informaiton? – πάντα ῥεῖ Jan 30 '21 at 16:21

1 Answers1

1

In general, yes; otherwise, your code won't compile.

But when writing C++ there is always these considerations:

  1. Do you put the include in your header or the cpp file? If your class or function header file doesn't require the include, then put it in your cpp file. This reduces compile time dependencies.
  2. Does your file include another header file that includes the list header? If for instance you have a cpp file that uses some header (e.g. ListUtils.hpp) that already includes the list header, then you may decided not to explicitly include the list header.
Anon Mail
  • 4,660
  • 1
  • 18
  • 21