C++ - avoiding the implicit inlining of a function defined in the class definition
<p>In my implementation files (.cc files), I often find that it's convenient to define member functions in class definitions (such as the functions of a Pimpl class). For example:</p>

<pre><code>struct X::Impl {
    void DoSomething() {
        ...
    }
};
</code></pre>

<p>instead of</p>

<pre><code>struct X::Impl {
    void DoSomething();
};

void X::Impl::DoSomething() {
    ...
}
</code></pre>

<p>I think this is preferable to implementing the function outside of the class definition for several reasons. It enhances readability and facilitates the practice of keeping methods small (by making it easy to add them). The code is also easier to maintain since you never have to update method declarations.</p>

<p>The only downside I see is that methods defined in the class declaration are implicitly inlined, which is not usually desirable because of the increase in the size of the object code.</p>

<p>My questions are:</p>

<ol>
<li><p>Do I have this right? Are there other downsides to this practice that I'm missing?</p></li>
<li><p>Is the implicit inlining something to worry about? Is the compiler smart enough to reject my implicit request to inline methods that shouldn't be inlined?</p></li>
<li><p>Is it possible (via compiler extensions or otherwise) to declare that a method defined in the class definition not be inlined?</p></li>
</ol>
