我读到它可以创建模板方法。我的代码中有这样的东西
文件:学生.h
class Student
{
public:
template<class typeB>
void PrintGrades();
};
文件:Student.cpp
#include "Student.h"
#include <iostream>
template<class typeB>
void Student::PrintGrades()
{
typeB s= "This is string";
std::cout << s;
}
现在在 main.cpp
Student st;
st.PrintGrades<std::string>();
现在我得到一个链接器错误:
Error 1 error LNK2019: unresolved external symbol "public: void __thiscall Student::PrintGrades<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(void)" (??$PrintGrades@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Student@@QAEXXZ) referenced in function _main
关于我可能做错了什么的任何建议?