[英]Cannot instantiate overloaded templated function
我有一个名为Hashtable
的类,其中包含几种用于批量加载输入数据的方法。 这些方法中的每一个都通过模板支持不同的文件格式,并且也被重载,因此可以使用字符串(文件名)或解析器对象作为其第一个参数来调用它。
这是一个例子。 像这样,在类头中定义了consume_seqfile
方法。
template<typename SeqIO>
void consume_seqfile(
std::string const &filename,
unsigned int &total_reads,
unsigned long long &n_consumed
);
template<typename SeqIO>
void consume_seqfile(
read_parsers::ReadParserPtr<SeqIO> &parser,
unsigned int &total_reads,
unsigned long long &n_consumed
);
然后像这样在类定义文件的底部实例化。
template void Hashtable::consume_seqfile<FastxReader>(
std::string const &filename,
unsigned int &total_reads,
unsigned long long &n_consumed
);
template void Hashtable::consume_seqfile<FastxReader>(
ReadParserPtr<FastxReader>& parser,
unsigned int &total_reads,
unsigned long long &n_consumed
);
这一切都很好,并且已经持续了几个月。 我现在正在尝试添加具有附加参数的此方法的新变体。 像这样在标头中定义它。
template<typename SeqIO>
void consume_seqfile_with_mask(
std::string const &filename,
Hashtable* mask,
unsigned int &total_reads,
unsigned long long &n_consumed
);
template<typename SeqIO>
void consume_seqfile_with_mask(
read_parsers::ReadParserPtr<SeqIO>& parser,
Hashtable* mask,
unsigned int &total_reads,
unsigned long long &n_consumed
);
像这样在源文件中实例化。
template void Hashtable::consume_seqfile_with_mask<FastxReader>(
std::string const &filename,
Hashtable* mask,
unsigned int &total_reads,
unsigned long long &n_consumed
);
template void Hashtable::consume_seqfile_with_mask<FastxReader>(
ReadParserPtr<FastxReader>& parser,
Hashtable* mask,
unsigned int &total_reads,
unsigned long long &n_consumed
);
但是,当我尝试编译时,出现以下错误消息。
src/oxli/hashtable.cc:635:26: error: explicit instantiation of undefined function template 'consume_seqfile_with_mask'
template void Hashtable::consume_seqfile_with_mask<FastxReader>(
^
include/oxli/hashtable.hh:281:10: note: explicit instantiation refers here
void consume_seqfile_with_mask(
我的Google / StackOverflow技能使我失望。 任何想法可能导致此问题?
更新 :问题出在代码未显示。 我确实有一个函数定义,但是它缺少用于命名空间的适当的Hashtable::
前缀。 因此...该函数确实未定义。 通过正确包含命名空间可以解决问题。
您声明了这些函数并在以后显式实例化了这些函数,但是您实际上有该函数的定义吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.