I was looking through The C++ Programming Language today and I noticed it said that functions defined inside the class definition (rather than outside it and qualified with Classname::) are automatically taken to be inline functions.
Is there any way to take this behaviour off for a particular function? Like an 'uninline' prefix would do if it existed?
AFAIK, there is no such thing as uninline. Why would you want to do it? Just like with non-member functions, it's only a hint to the compiler, so the function(s) may not be inlined (especially if it's too complex or is declared virtual).
There are compiler-specific attributes that can be used on function declarations which explicitly tell the compiler not to in-line a function regardless of where and how it's declared. In-line expansion is disabled by default with Microsoft's compiler, but with GCC, there's an attribute to explicitly stop in-lining:
@Disch, yeah, you are right. Invoking a v-function directly (not through a pointer/reference) actually makes the compiler treat the function as non-virtual.
Thanks for these answers. As to why I'd want to do it - I like to define member functions inside the class because I think it looks tidier. But I didn't like to think of the compiler generating awkward code to inline a function that isn't suitable to be inline.
But if the inline-ness of functions defined inside the class is just a hint, it doesn't matter.
> I like to define member functions inside the class because I think it looks tidier
It really doesn't unless the function is very small; but I suppose that is a matter of opinion.
That defining every member function inside every class creates needless compile-time coupling is a not a matter of opinion, though.
> But if the inline-ness of functions defined inside the class is just a hint...
The inline specifier is not just a hint as far as ODR is concerned - an inline function with external linkage can be defined (identically) in multiple translation units.
The inline specifier as an optimization hint is completely ignored by mainstream compilers. With optimizations enabled, functions that are not declared inline may be inlined; and functions that are declared inline may not be inlined. The "as-if" rule is all that matters.