0

Im new to programming and Im trying out some simple things with templates. I wrote a simple multiply function in an additional source file

#include<iostream>

template<typename T>
void Multiply(T a) {

    std::cout << 3 * a << std::endl;

}

with a header file with the decleration

   #pragma once
template<typename T>
void Multiply(T a);

If I try to compile this code I get a linking error, which makes sense to me because, if I understand correctly, the compiler cant compile the source code without knowing what T is. So my question is, why does my code work if I add #include "Multiply.cpp" to the header file? That doesnt make too much sense to me, but the code successfully compiles.

JanJHF
  • 1
  • 2

0 Answers0