[英]Cannot instantiate overloaded templated function
I have a class named Hashtable
with several methods for bulk-loading input data. 我有一个名为
Hashtable
的类,其中包含几种用于批量加载输入数据的方法。 Each of these methods supports different file formats via templates, and is also overloaded so that it can be called with either a string (filename) or a parser object as its first argument. 这些方法中的每一个都通过模板支持不同的文件格式,并且也被重载,因此可以使用字符串(文件名)或解析器对象作为其第一个参数来调用它。
Here is an example. 这是一个例子。 The
consume_seqfile
method is defined in the class header like so. 像这样,在类头中定义了
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
);
And then instantiated at the bottom of the class definition file like so. 然后像这样在类定义文件的底部实例化。
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
);
This all works fine, and has for months. 这一切都很好,并且已经持续了几个月。 I'm now trying to add a new variant of this method that has an additional argument.
我现在正在尝试添加具有附加参数的此方法的新变体。 It is defined in the header like so.
像这样在标头中定义它。
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
);
And instantiated in the source file like so. 像这样在源文件中实例化。
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
);
However, when I try to compile I get the following error message. 但是,当我尝试编译时,出现以下错误消息。
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(
My Google/StackOverflow skills are failing me. 我的Google / StackOverflow技能使我失望。 Any idea what might be causing this issue?
任何想法可能导致此问题?
UPDATE : The problem was with code not shown. 更新 :问题出在代码未显示。 I did have a function definition, but it lacked the proper
Hashtable::
prefix for namespacing. 我确实有一个函数定义,但是它缺少用于命名空间的适当的
Hashtable::
前缀。 So...the function was indeed undefined. 因此...该函数确实未定义。 Problem resolved by properly including the namespacing.
通过正确包含命名空间可以解决问题。
您声明了这些函数并在以后显式实例化了这些函数,但是您实际上有该函数的定义吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.