title: How does the compilation of templates work?
body: <p>I'm reading a book about how templates work, and I'm having difficulty understanding this explanation of templates.</p>
  <p>It says</p>
  <blockquote>
  <p>When the compiler sees the definition of a template, it does not <strong>generate code</strong>. It generates code only when we instantiate a specific instance of the template. The fact that code is generated only when we use a template (and not when we define it) affects how we organize our source code and when errors are detected...To generate an instantiation, the compiler needs to have the code that defines a function template or class template member function. As a result, unlike non-template code, headers for templates typically include definitions as well as declarations.</p>
  </blockquote>
  <p>What exactly does it mean by &quot;generate code&quot;? I don't understand what is different when you compile function templates or class templates compared to regular functions or classes.</p>