I have a question about header inclusion best practices when dealing with implicit type construction.
Consider the following code structure:
// a.h
struct A { int x, y; };
// b.h
#include "a.h"
struct B { void Func(A a) { /* use a */ } };
// c.cpp
#include "b.h"
void Func() {
B b;
b.Func({1, 2}); // Implicit construction of A
}
In c.cpp, we're using struct A implicitly through brace initialization, and the compiler successfully deduces the type for us because b.h includes a.h. This pattern is common when working with aggregate types.
Questions:
Should we explicitly include a.h in c.cpp even though we're not directly referencing the symbol?
What's the general consensus for header inclusion when dealing with implicit type construction?
I have a question about header inclusion best practices when dealing with implicit type construction.
Consider the following code structure:
In
c.cpp
, we're using structA
implicitly through brace initialization, and the compiler successfully deduces the type for us becauseb.h
includesa.h
. This pattern is common when working with aggregate types.Questions:
a.h
inc.cpp
even though we're not directly referencing the symbol?I'd appreciate insights on this scenario.