For curiosity's sake, if you put the method definition inside the class definition in the header, and the compiler doesn't inline it, then what object file or files is that method put into for accessing during the linker phase? Is it put in every .obj file that includes the header, and then extra copies are thrown away during the linker phase?
Is it put in every .obj file that includes the header, and then extra copies are thrown away during the linker phase?
In general, yes. See this paper.
It depends on the compiler, but GCC at least will try to place it in the same object file as the first non-inline member. If all members are inline, then there will be a copy in every object file that requires the function (not necessarily all files that include the class definition), and the extra copies are thrown away during linking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With