我有这样的令牌列表类:
#include "token.hpp"
class TokenList
{
template <typename... ArgsT>
Token expect(int &err, ArgsT... types);
Token expectTypes(int &err, std::initializer_list<int> types);
};
Token TokenList::expectTypes(int & err, std::initializer_list<int> types)
{
// do thing
}
template <typename... ArgsT>
Token TokenList::expect(int & err, ArgsT... types)
{
return expectTypes(err, {types...});
}
从这些方法返回的令牌类:
enum Types
{
NONE,
IDENTIFIER,
INSTRUCTION
};
class Token
{
int type = 0;
int location = 0;
// some other members
}
主要是:
#include "token_list.cpp"
int main(int argc, char *argv[])
{
TokenList t;
Token tok = tk.expect(state.error, IDENTIFIER);
}
当我尝试编译时,我得到编译器抱怨-
undefined reference to `Token TokenList::expect<Types>(int&, Types)'.
该功能已明确定义,并且包含标头。我遗漏了什么导致此未定义引用?