Witam,
Chciałbym sobie zrobić specjalizację szablonu w zależności od tego jaki RequestType wtedy wywoła się odpowiednia metoda, natomiast poniższy kod nie kompiluje się z błędem:
test.cpp:21:6: error: template-id ‘get<Highscore>’ for ‘void Foo::get()’ does not match any template declaration
void Foo::get<RequestType::Highscore>()
^~~
test.cpp:16:7: note: candidate is: template<class Type> void Foo::get()
void get();
^~~
test.cpp: In function ‘int main()’:https://4programmers.net/Forum/C_i_C++/Submit#body
test.cpp:30:34: error: no matching function for call to ‘Foo::get<Highscore>()’
foo.get<RequestType::Highscore>();
^
test.cpp:16:7: note: candidate: template<class Type> void Foo::get()
void get();
^~~
test.cpp:16:7: note: template argument deduction/substitution failed:
#include <iostream>
enum class RequestType
{
Highscore,
Players,
Unknown = -1
};
class Foo
{
public:
Foo() = default;
template<typename Type>
void get();
};
template<>
inline void Foo::get<RequestType::Highscore>()
{
std::cout << "Highscore" << std::endl;
}
int main()
{
Foo foo;
foo.get<RequestType::Highscore>();
return 0;
}
I nie bardzo wiem dlaczego? Ktoś pomoże?