On 1 March 2011 03:53, Ian Lance Taylor wrote: > Jonathan Wakely <jwakely.gcc@xxxxxxxxx> writes: > >> On 1 March 2011 00:25, Ian Lance Taylor wrote: >>> "Kevin P. Fleming" <kpfleming@xxxxxxxxxx> writes: >>> >>>> I would like to come up with some construction like the 'extern >>>> inline' that GCC supports for C mode, so that a.h could contain the >>>> declaration *and* definition of 'bar', allowing code that includes a.h >>>> to have 'bar' be inlined if the compiler chooses to do so (and leave >>>> an external reference to 'bar' if necessary so that the version built >>>> from a.cpp will be used). So far my attempts have only resulted in >>>> various re-definition or re-declaration errors. >>> >>> There is no equivalent to GNU C's "extern inline" in C++. By the way, >>> "extern inline" is now actually known as __attribute__ ((gnu_inline)), >>> as C99 defines "extern inline" to mean something different. >>> >>> In C++ you can simply define the function inline in a.h, and not define >>> it at all in a.cpp. The right thing will happen. >> >> That will work in practice, but it's technically an ODR violation. > > No, it's not (there may be a misunderstanding somewhere). I am > suggesting that there should be only one definition: the one in a.h. > That is OK if the definition has inline linkage. It is certainly not an > ODR violation, as there is only one definition. Yes sorry, I did misunderstand. But in that case a.h must be included by all callers of the function. I thought the point was some callers don't want to include the definition of the class and the function that uses it.