简体   繁体   中英

Cannot instantiate overloaded templated function

I have a class named Hashtable with several methods for bulk-loading input data. 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.

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. 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. So...the function was indeed undefined. Problem resolved by properly including the namespacing.

您声明了这些函数并在以后显式实例化了这些函数,但是您实际上有该函数的定义吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM