Guest User

Untitled

a guest
Jan 24th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. class MyClass
  2. {
  3. public:
  4. MyClass(){}
  5.  
  6. template<typename T>
  7. void templateFunction1(T x);
  8.  
  9. template<typename T>
  10. void templateFunction2(T* x);
  11. };
  12.  
  13. template<typename T>
  14. void MyClass::templateFunction1(T x){
  15. std::cout << x << std::endl;
  16. }
  17.  
  18. template<typename T>
  19. void templateFunction2(T* x){
  20. std::cout << (*x) << std::endl;
  21. }
  22.  
  23. int main(){
  24.  
  25. int i = 1;
  26. float f = 1.232;
  27. std::string s = "string";
  28. char* c = "char arr";
  29.  
  30. MyClass myObj;
  31. /*This works:*/
  32. myObj.templateFunction1(i);
  33. myObj.templateFunction1(f);
  34. myObj.templateFunction1(s);
  35. myObj.templateFunction1(c);
  36.  
  37. /*This does not work:*/
  38. myObj.templateFunction2(&i);
  39. myObj.templateFunction2(&f);
  40. myObj.templateFunction2(&s);
  41. myObj.templateFunction2(&c);
  42.  
  43. return 0;
  44. }
  45.  
  46. LNK2019: unresolved external symbol "public: void __thiscall MyClass::templateFunction2<int>(int *)" (??$templateFunction2@H@MyClass@@QAEXPAH@Z) referenced in function _main D:VS2013_Projectstest_projectstemplateMemberFunctionTesttemplateMemberFunctionTestmain.obj
Add Comment
Please, Sign In to add comment