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?
For curiosity’s sake, if you put the method definition inside the class definition in
Share
If the compiler rejects inlining some member function that is defined in-line in the body of the class or is defined as an
inlinefunction outside the body of the class, the compiler will insert a compiled version of the function in every .obj file that uses that function. Note that this is different from inserting a compiled version of every function declared in the header. The file in question has to invoke that (supposedly) inline function.And yes, the linker will delete duplicate entries. The symbols generated in the symbol table for these inlined functions have weak linkage. Compare to functions that aren’t inlined: They have normal linkage, and if one of those is replicated you have undefined behavior. The typical response is for the linker to complain and then die.