title: Inline member functions in C++
body: <p>ISO C++ says that the inline definition of member function in C++ is the same as declaring it with inline. This means that the function will be defined in every compilation unit the member function is used. However, if the function call cannot be inlined for whatever reason, the function is to be instantiated "as usual". (<a href="http://msdn.microsoft.com/en-us/library/z8y1yy88%28VS.71%29.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/z8y1yy88%28VS.71%29.aspx</a>) The problem I have with this definition is that it does not tell in which translation unit it would be instantiated.
  The problem I encountered is that when facing two object files in a single static library, both of which have the reference to some inline member function which cannot be inlined, the linker might "pick" an arbitrary object file as a source for the definition. This particular choice might introduce unneeded dependencies. (among other things)</p>
  
  <p>For instance:
  <strong>In a static library</strong></p>
  
  <pre><code>A.h:
  
  class A{
    public:
      virtual bool foo() { return true; }
  };
  </code></pre>
  
  <p>U1.cpp:</p>
  
  <pre><code>A a1;
  </code></pre>
  
  <p>U2.cpp:</p>
  
  <pre><code>A a2;
  </code></pre>
  
  <p><em>and lots of dependencies</em></p>
  
  <p><strong>In another project</strong>
  main.cpp:</p>
  
  <pre><code>#include "A.h"
  
  int main(){
    A a;
    a.foo();
    return 0;
  }
  </code></pre>
  
  <p>The second project refers the first. How do I know which definition the compiler will use, and, consequently which object files with their dependencies will be linked in? Is there anything the standard says on that matter? (Tried, but failed to find that)</p>
  
  <p>Thanks</p>
  
  <p>Edit: since I've seen some people misunderstand what the question is, I'd like to emphasize: <em>If the compiler decided to create a symbol for that function (and in this case, it will, because of 'virtualness', there will be several (externally-seen) instantiations in different object file, which definition (from which object file?) will the linker choose?)</em></p>