Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyClass
- {
- public:
- MyClass(){}
- template<typename T>
- void templateFunction1(T x);
- template<typename T>
- void templateFunction2(T* x);
- };
- template<typename T>
- void MyClass::templateFunction1(T x){
- std::cout << x << std::endl;
- }
- template<typename T>
- void templateFunction2(T* x){
- std::cout << (*x) << std::endl;
- }
- int main(){
- int i = 1;
- float f = 1.232;
- std::string s = "string";
- char* c = "char arr";
- MyClass myObj;
- /*This works:*/
- myObj.templateFunction1(i);
- myObj.templateFunction1(f);
- myObj.templateFunction1(s);
- myObj.templateFunction1(c);
- /*This does not work:*/
- myObj.templateFunction2(&i);
- myObj.templateFunction2(&f);
- myObj.templateFunction2(&s);
- myObj.templateFunction2(&c);
- return 0;
- }
- 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