Daniel Standage Daniel Standage - 1 year ago 59
C++ Question

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.

Answer Source

You declare these functions and explicitly instantiate it later, but do you actually have a definition for the function?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download