Saya perlu mengkhususkan fungsi anggota template untuk beberapa jenis (katakanlah ganda ). Ini berfungsi dengan baik sementara kelas Xitu sendiri bukan kelas template, tetapi ketika saya membuatnya, template GCC mulai memberikan kesalahan waktu kompilasi.
#include <iostream>
#include <cmath>
template <class C> class X
{
public:
template <class T> void get_as();
};
template <class C>
void X<C>::get_as<double>()
{
}
int main()
{
X<int> x;
x.get_as();
}
ini pesan kesalahannya
source.cpp:11:27: error: template-id
'get_as<double>' in declaration of primary template
source.cpp:11:6: error: prototype for
'void X<C>::get_as()' does not match any in class 'X<C>'
source.cpp:7:35: error: candidate is:
template<class C> template<class T> void X::get_as()
Bagaimana cara memperbaikinya dan apa masalahnya di sini?
Terima kasih sebelumnya.