mercredi 24 juin 2020

Why i can't linking two template functions in c++ [duplicate]

I have two files cpp.

main.cpp:

 #include <iostream>
 using namespace std;

 template<typename T>
 void func(T a);

 int main(){

   func<int>(15);

   return 0; 
}

main_2.cpp:

#include <iostream>
using namespace std;

   template<typename T>
   void func(T a){
   cout << a << endl;
   }

When i compile and link them. The compiler said that :

C:\Users\Lenovo\CodeBlocks\kenangan_2\main.cpp|9|undefined reference to `void func<int>(int)'|

How to resolve this problem?

Thanks in advance....

Aucun commentaire:

Enregistrer un commentaire