2017-07-26 114 views
1

我有一個名爲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技能讓我失望。任何想法可能導致這個問題?

UPDATE:問題是與代碼未示出。我有一個函數的定義,但是,它缺乏對命名空間的正確Hashtable::前綴。所以...這個函數確實沒有定義。通過正確包含命名空間解決問題。

回答

0

您聲明瞭這些函數,並在稍後顯式實例化它,但是實際上是否有函數的定義?

+0

是,也不是。查看更新。該函數已被定義,但我意外地省略了命名空間。填補,解決了這個問題。 –