6

Próbuję częściowo specjalizują się szablonie funkcji członkiem untemplated zajęć:Częściowa specjalizacja szablonu z funkcji członka: „prototyp nie pasuje”

#include <iostream> 

template<class T> 
class Foo {}; 

struct Bar { 

    template<class T> 
    int fct(T); 

}; 

template<class FloatT> 
int Bar::fct(Foo<FloatT>) {} 


int main() { 
    Bar bar; 
    Foo<float> arg; 
    std::cout << bar.fct(arg); 
} 

Dostaję następujący błąd:

c.cc:14: error: prototype for ‘int Bar::fct(Foo<FloatT>)’ does not match any in class ‘Bar’ 
c.cc:9: error: candidate is: template<class T> int Bar::fct(T) 

Jak mogę naprawić błąd kompilatora?

Odpowiedz

9

Częściowa specjalizacja funkcji (członek lub inny) jest niedozwolona.

użycie przeciążenie:

struct Bar { 

    template<class T> 
    int fct(T data); 

    template<class T> //this is overload, not [partial] specialization 
    int fct(Foo<T> data); 

}; 
Powiązane problemy