You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a question about header inclusion best practices when dealing with implicit type construction.
Consider the following code structure:
// a.h structA { int x, y; };
// b.h
#include"a.h"structB { voidFunc(A a) { /* use a */ } };
// c.cpp
#include"b.h"voidFunc() {
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'd appreciate insights on this scenario.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: