4 ms·
No, C++ header files contain definitions too, which are emitted into every object file where they're used. If it's something allowed to be multiply defined it's
by tlb 3y ago
No, C++ header files contain definitions too, which are emitted into every object file where they're used. If it's something allowed to be multiply defined it's emitted as a "weak" symbol, and the linker eliminates duplicates.
This includes every inline function that's used, and many default-generated functions, such as default constructors & destructors and virtual function tables.
For a simple example, See https://godbolt.org/z/qhvaP8Eed https://godbolt.org/z/qhvaP8Eed and observe the Foo::Foo() constructor, which would be emitted in every .o file with the 'struct Foo' definition.
- astrobe_ 3y agoOk, thanks for the correction.