Rule A16-2-3 (required, implementation, non-automated)
An include directive shall be added explicitly for every symbol used in a file.
Rationale
All header files that define types or functions used in a file should be included explicitly. The actual header to include depends on the specification of the library/component used.
Exception
Types defined via forward declarations do not violate this rule.
Example
// $Id: A16-2-3.hpp 319944 2018-05-21 09:00:40Z ilya.burylov $
#ifndef HEADER_HPP
#define HEADER_HPP
#include <array>
#include <cstdint>
class B; // Compliant - type B can be included using forward declaration
class OutOfRangeException
: public std::out_of_range // Non-compliant - <stdexcept> which defines
// out_of_range included
// implicitly through <array>
{
public:
using std::out_of_range::out_of_range;
};
class A
{
public:
// Interface of class A
private:
std::array<std::uint32_t, 10>
mArray; // Compliant - <array> included explicitly
B* mB;
std::int32_t mX; // Compliant - <cstdint> included explicitly
};
#endif
See also
none