我有类帐户的以下成员函数:
void account::list_collection() {
list_gtoons(collection.begin(), collection.end());
}
调用以下模板:
template<class For> void list_gtoons(For begin, For end) {
while (begin != end) {
(begin++)->print();
}
}
调用gtoon成员函数print():
void gtoon::print() const {
cout << name << " " << color << " " << value << endl;
}
我收到以下错误:
1>account.obj : error LNK2019: unresolved external symbol "public: void __thiscall gtoon::print(void)const " (?print@gtoon@@QBEXXZ) referenced in function "void __cdecl list_gtoons<class std::_List_iterator<class std::_List_val<class gtoon,class std::allocator<class gtoon> > > >(class std::_List_iterator<class std::_List_val<class gtoon,class std::allocator<class gtoon> > >,class std::_List_iterator<class std::_List_val<class gtoon,class std::allocator<class gtoon> > >)" (??$list_gtoons@V?$_List_iterator@V?$_List_val@Vgtoon@@V?$allocator@Vgtoon@@@std@@@std@@@std@@@@YAXV?$_List_iterator@V?$_List_val@Vgtoon@@V?$allocator@Vgtoon@@@std@@@std@@@std@@0@Z)
似乎删除(begin++)->print();
修复了问题,但我不确定为什么错误发生在第一位。