title: Why doesn't this generate duplicate symbols for linker?
body: <p>Let's assume the following code:</p>
  
  <pre><code>// IInterface.h
  
  #pragma once
  
  class IInterface
  {
    public:
    struct Thing
    {
      // If i uncomment this line, I can see that all object files increase in size.
      // char data[10240];
      int getOne() { return 1;}
    };
    // The interface doesn't really matter
  };
  </code></pre>
  
  <hr>
  
  <pre><code>// Derived1.h
  #pragma once
  #include "IInterface.h"
  
  class Der1: public IInterface
  {
    public:
    int getOne();
  };
  </code></pre>
  
  <hr>
  
  <pre><code>// Derived2.h
  #pragma once
  #include "IInterface.h"
  
  class Der2: public IInterface
  {
    public:
    int getOne();
  };
  </code></pre>
  
  <hr>
  
  <pre><code>// Derived1.cpp
  #include "Derived1.h"
  
  int Derived1::getOne()
  {
    Thing thing;
    return thing.getOne();
  }
  </code></pre>
  
  <hr>
  
  <pre><code>// Derived2.cpp
  #include "Derived2.h"
  
  int Derived2::getOne()
  {
    Thing thing;
    return thing.getOne();
  }
  </code></pre>
  
  <hr>
  
  <pre><code>// main.cpp
  
  // Not really needed I guess?
  
  #include "Derived1.h"
  #include "Derived2.h"
  
  int main(int argc, char* argv[])
  {
    Der1 der1;
    Der2 der2;
  
    return der1.getOne() - der2.getOne();
  }
  </code></pre>
  
  <p>Now I'm not sure how to put this question to words, but here I go.</p>
  
  <p>Why doesn't the method IInterface::Thing::getOne generate linker errors because it has multiple versions of it in different translation units?</p>
  
  <p>If I made a version where getOne is just a global function declared and defined in IInterface.h, that would generate linker errors.</p>
  
  <p>I know I could move the struct to a separate .cpp file, but since it's IInterface and I'm using C++17, I don't need a .cpp file. There isn't one.</p>
  
  <p>Oh and I'm on MSVC 2019. But I'm interested if this code works for GCC, or other compilers. I'll have to run some tests.</p>