簡體   English   中英

無法實例化重載的模板化函數

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM